• 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

HTML and PHP in one file

How to Make Laravel Eloquent "IN" Query?

google content api for shopping

How to show selected value using javascript in laravel

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

How to find phpcs current default standard

How to send upload image through email

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

How avoid Moved Permanently The document has moved here

PHP/HTML: Creating A SubMenu

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

Make survey at laravel 5.4 and MySQL

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

OctoberCMS / Anonymous Global Scope

What is PHP's equivalent of JavaScript's "array.every()"?

About Contact Privacy policy Terms and conditions