• 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

Get image type from base64 encoded src string

PHP DOTENV unable to load env vars

Set quantity minimum, maximum and step at product level in Woocommerce

How can I create a Download Page with post php method?

XML to CSV with PHP converter [problem with images grabing]

Phalcon: setStatusCode returns empty response

Laravel UUID generation

Eloquent insert id with sequence next value

Laravel dosen't connect with Oracle

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Is there a way to use Foundry Model for Authentification inside Functional Tests?

Change user role if checkout custom checkbox is checked in WooCommerce

Need to display only array value in JSON output

Trying to iterate over a mongodb cursor twice - failing

Using PHP to connect to a remote MSSQL database

About Contact Privacy policy Terms and conditions