• 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

Update Total in checkout of Woocommerce with Ajax Request

Could not decode a text frame as UTF-8.

PHP using str_starts_with for array to exclude same as with wildcard

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Unable to match results of php hash_hmac() and coldfusion hmac()

Create a zip file and download it

Invalid value in field "itemtype" in Google Search Console

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Adding one microsecond to Datetime object in PHP

Group rows by column and sum another column within groups [duplicate]

Calculating Median of an array in PHP

SMTP "Error: DATA not accepted from server!" Opencart 2.3 on InMotionHosting

Laravel websockets AWS EC2 - Connection failed

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

Add 2 Webcam in one page with WebcamJS

About Contact Privacy policy Terms and conditions