• 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

Call to a member function givePermissionTo() on null

Calculating Median of an array in PHP

Detect if PHP session exists

Facebook SDK error: Cross-site request forgery validation failed. Required param "state" missing from persistent data

"properties should not be accessed directly" issue during WooCommerce 3.0 checkout

add_action() function in wordpress not working [duplicate]

Extract string between first whitespace and last whitespace in php

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

Laravel Unknown Column 'updated_at'

PHP-Sort array based on another array?

Laravel Nova, route not found

Prestashop cUrl Login

How to use $this->session->set_userdata in codeigniter

Create tags in laravel post publishing

Merge key and value of array index [duplicate]

About Contact Privacy policy Terms and conditions