• 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

Pass an image through AJAX [duplicate]

Calculating Median of an array in PHP

How to loop a tree array with unknown depth and get array blocks?

Unable to match results of php hash_hmac() and coldfusion hmac()

Add customer email and phone in "Order" column to admin orders list on Woocommerce

Appending data to an anchor tag

WooCommerce - unset "<product> removed notice…" on cart page

how to see if database exists with PDO [duplicate]

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

How to redirect to another page after n seconds in wordpress without using javascript?

PHP-Sort array based on another array?

Convert every two values of an associative array into key-value pairs

mysql slow on updates for a well optimized query

Laravel 8 Multiple Relationships for Factory

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

About Contact Privacy policy Terms and conditions