• 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

Results page in other window

PHP drop down list using array's and foreach (else and for) code

Read users and passwords from a txt file

How to disable only_full_group_by option in Laravel

Get sum of arrays inside array

Sort multidimensional array by column value within a column

hidden INPUT value not available in $_POST

Match single unknown parameter php (Morse-code Regex)

How can I remove the "Advanced" panel of all blocks in WordPress block editor?

Two buttons one form

Laravel Schedule not sending email

How to trim a video by 4 fragments to 4 seconds using the PHP-FFMpeg?

Access relation of pivot table in Laravel

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

How to display table header in every page using FPDF library?

About Contact Privacy policy Terms and conditions