• 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

SilverStripe unable to populate multiple member Childs

PHP Fatal error: Class not found - PHPUnit

How to write PHP in XSLT

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

Update Order custom Field value with WooCommerce REST API

How to show selected value using javascript in laravel

How to add a custom field to all Woocommerce attribute terms using add_action

Login if user is active using Laravel Breeze

Lumen - Postgresql setup - Composer

Laravel SQL query midnight time not showing

Laravel UUID generation

Navigation idle on content download

Laravel whole batch is cancelled if one Job fails

Split comma separated value from table column into rows using mysql?

Execute only one time and then wait set period of time before executing again

About Contact Privacy policy Terms and conditions