• 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

MySQL/PHP - Web Based Game -User specific inventory table or 1 giant table? Another option?

if statement inside concatenation

*** ERROR *** The PHP configuration loaded file is: c:/wamp64/bin/php/php8.1.0/php.ini - should be: c:/wamp64/bin/apache/apache2.4.53.1/bin/php.ini

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

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

WooCommerce Subscriptions: Remove role on cancelled subscription

Yii2 redirecting to previous page after login

Assets not referencing to public folder (Laravel)

merge all files in directory to one text file

args[max_input] woocommerce if statement confused

XAMPP keeps showing Dashboard/Welcome Page instead of the Configuration Page

How to make Canonicals with PHP

Edit XML in HTML form and submit to self

How do I remove this delivery notification from here?

Inserting data into SQL Server Db An Invalid direction was specified

About Contact Privacy policy Terms and conditions