• 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

Input and output values for php into the browser?

OctoberCMS / Anonymous Global Scope

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

MySQL default time format UTC or GMT?

Laravel 5 controller sending JSON integer as string

Getting error: CodeIgniterDatabaseBaseResult::getResult in CodeIgniter

I want to display default profile image if user do not have profile image

Facebook PHP SDK - will not logout properly

PHP drop down list using array's and foreach (else and for) code

How can I easily switch between PHP versions on Mac OSX?

Installing Composer - Internal Error

Post Form Data To phpmyadmin Database

how to insert data into select2 search input after scan using qrcode

How can I get a div content in php

Create tags in laravel post publishing

About Contact Privacy policy Terms and conditions