• 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

WHERE IN array binding in DB::raw laravel 5.4

Laravel Sanctum CSRF not authenticating

Cache clear probem in Larave

Error converting docx to pdf using Unoconv

generate an Excel file using PHP

Display the default discounted price and percentage on Woocommerce products

PHP array_filter with arguments

PHP random string generator

PHP and WebView - Cookie doesn't are the same

How to run or debug php on Visual Studio Code (VSCode)

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

"Unable to load dynamic library 'pdo_sqlsrv.so' "Cenos7 PHP7.2.10

Unable to Edit config.inc.php

php file upload scanning using clamav, permissions on /tmp/

Boolean assignment operators in PHP

About Contact Privacy policy Terms and conditions