• 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

WHERE IN array binding in DB::raw laravel 5.4

Adding custom body class to the custom archive pages

WAMP Virtual Host not working

Clear javascript source cache laravel 5.8

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

php file upload scanning using clamav, permissions on /tmp/

The "client_reference_id" argument is not passed

How to properly start Laravel 8 with Bootstrap & authentication

php echo xml documents with header

Laravel Jetsream Profile page not loading on fresh install

Laravel Sanctum CSRF not authenticating

Laravel - Browser displays message again when I press back button

Laravel 8: Array to string conversion while calling route:list

Respond with status code 401 on authentication failure using Laravel and Passport?

Laravel Pagination links() not working

About Contact Privacy policy Terms and conditions