• 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

retrieve data from database using session

How to average columns of data from multiple, flat arrays?

Laravel 5.5 change unauthenticated login redirect url

How to KeyBy where multiple items have the same key

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

How to make a foreign key not using primary key

Laravel s3 upload file with metadata using pre-signed url

How to Display Data in Yajra Datatables Laravel 7?

No result using makeStyles Material UI in react 18

SlimExceptionHttpNotFoundException

How to break out of a foreach once a condition is met?

protect my blog content

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

Populate Dynamic Dropdowns List in Codeigniter

About Contact Privacy policy Terms and conditions