• 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

How do I enable error reporting in Laravel?

How to insert Google Adsense Code in PHP script?

SendGrid: Sending an email to multiple recipients without other emails being shown on the "to" field

wordpress : How to specify the cause "This site can’t be reached"

find in set in laravel ? example

Losing session data after POST from third party website

How can I easily switch between PHP versions on Mac OSX?

php curl requesting twice

Laravel Delete and Update

How in Laravel run JavaScript code stored in php variable?

Message: Set sys_temp_dir in your php.ini after installed composer

Symfony/Form add attribute based on the data

Object of class stdClass could not be converted to string error

500 (Internal Server Error) with Laravel & Docker [duplicate]

How to change HTML structure inside WP <head>

About Contact Privacy policy Terms and conditions