• 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

Split array into 4-element chunks then implode into strings

Remove categories with all childs derived from parent category

Laravel Factory not calling callback 'afterCreating'

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

How to add a heading in between checkout fields of WooCommerce

Match csv filenames to table names and import

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

PHP: Print caught exception like Xdebug

Check if my GET request has Header: Token

Symfony 4: "Autowire: you should configure its value explicitly."

Merge column values from two arrays to form an indexed array of associative arrays

Search for array row with specific column value and return another value from qualifying row

How to access a var with "-" in PHP [duplicate]

Best way to scrolldown onpageload

php script to delete files older than 24 hrs, deletes all files

About Contact Privacy policy Terms and conditions