• 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

How to modify CSS in a specific page of the WP admin dashboard (backend)

IlluminateDatabaseQueryException could not find driver [duplicate]

How to add automatically collapse/expand in content wordpress (single.php)?

How do I truncate a decimal in PHP?

How to change the app environment at run time?

Laravel PHP: multiple project run at the same time [closed]

Laravel after login Two factor not working

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

Detect if PHP session exists

Implode array with array of glue strings

How to get multiple values with same key from an array PHP

How to create a scheduler application in php

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

Google Gmail API - How to login programatically?

About Contact Privacy policy Terms and conditions