• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

str_replace or preg_replace random number from string

phppreg-replacestr-replace


PHP Snippet 1:

$id = $_GET["id"]

PHP Snippet 2:

$url = "http://anyurl/index.php?id=".$id."&abc=any"

PHP Snippet 3:

<?php
$string = 'http://anyurl/index.php?id=4876&abc=any';
$new_string = preg_replace('/[0-9]+/', $_GET["id"], $string);
echo $new_string;
// Will display http://anyurl/index.php?id=3345&abc=any 
?>

Related Snippets

Prevent blank space in pdf pages (DomPdf)

Laravel Livewire: jQuery not working in child component loaded via @if statement

PHPS source file - 403 Forbidden You don't have permission to access this resource

Facebook API, get page post link (PHP)

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

Redirect to previous page with php

How to send image,audio or video through the WhatsApp API - PHP

Prestashop cUrl Login

php - add comma thousands separator but remove trailing zeros

How to convert the int value to inch in PHP [closed]

how to make my own auto increment in php?

mysql_result is defined but mysql_free_result warns it expected a resource

Laravel s3 upload file with metadata using pre-signed url

Shopify password update using Shopify API

Laravel Schedule not sending email

About Contact Privacy policy Terms and conditions