• 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

Confirm Leave on External Links in Wordpress

Fetch files from next cloud storage and display in Laravel website

I cannot create a auto generated date time in mysql workbench

Edit product hook WooCommerce

How do I get friend list from Friends table with counts of friends of my friends

How to disable widget block editor of WordPress?

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

PHP: PDO + CSV export not downloading (headers issue?)

Change the alert text on add to cart action without selected variation in Woocommerce

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

Having issue with matching rows in the database using PDO

Hide email address with stars (*)

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

How to add a heading in between checkout fields of WooCommerce

Laravel display validation error

About Contact Privacy policy Terms and conditions