• 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

Get data from accuweather api url

Set quantity minimum, maximum and step at product level in Woocommerce

Display specific shipping method if woocommerce product has specific acf field value

echo language construct is discouraged. (PHP)

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Implode array with array of glue strings

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Chunk and transpose a flat array into rows with a specific number of columns

Pages are working fine on localhost but not running on the hosting server

Login if user is active using Laravel Breeze

Add Metadata, headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 5.0 Storage facade

Laravel no logout option from menu after successfull login

Apply filter array/return terms

Laravel Get Days In Month From Month Number?

Laravel Sanctum CSRF not authenticating

About Contact Privacy policy Terms and conditions