• 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

Unable to Edit config.inc.php

Generate random username based on full name php

PHP Form Not Inserting

Getting output of MS stored procedure on php call

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

PHP array, move keys and values to new array, but mix it up

Laravel Collections. Is there some kind of assertStructure method?

Can we define variables in `.tpl` files?

Detect emoticons in string

Limit login attempts in Laravel 5.7

hidden INPUT value not available in $_POST

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

Printing more than one array using print_r or any other function in php

merge all files in directory to one text file

About Contact Privacy policy Terms and conditions