• 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 can I get a div content in php

Target Individual Form Instance/Counter Inside A PHP While Loop

Merge key and value of array index [duplicate]

MongoDB Duplicate Documents even after adding unique key

mysql slow on updates for a well optimized query

how do i retrieve and display the alt text of an image in wordpress?

Make survey at laravel 5.4 and MySQL

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables 11 [closed]

Exact alternate to mcrypt_encrypt in PHP 7.2

Check for PDO Results, If None Display Message, If Yes then Loop Through

Return multiple values from a function using mysqli_fetch_assoc [closed]

Last order would be re-order in wooCommerce. How is it possible?

SendGrid: Sending an email to multiple recipients without other emails being shown on the "to" field

Laravel Collections. Is there some kind of assertStructure method?

About Contact Privacy policy Terms and conditions