• 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

Laravel 5 session not persisting after user is logged in

Appending data to an anchor tag

How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?

How to get variable from JavaScript to PHP [duplicate]

Show date difference as "20" instead of "20 years ago"

printing all running session variable in laravel 5.1

500 Internal Server Error on Ajax request. Not sure the origin of the problem

Return new collection without modifying original collection

How can I get new CSRF token in LARAVEL by using ajax

Additional price based on cart item count in WooCommerce

send email using gmail-api and google-api-php-client

Doctrine ORM: Excluding Records Based on Values of Nested Relationships

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

Stop caching for PHP 5.5.3 in MAMP

SQLSTATE[HY000]: General error: 1 table posts has no column named *

About Contact Privacy policy Terms and conditions