• 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

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

How to render html from a @foreach loop in a textarea

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Fatal error: Array callback has to contain indices 0 and 1

browsersync doesn't work with XAMPP

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

Extract string between first whitespace and last whitespace in php

(Cache::lock()) -> get() -- Under what conditions does it return false?

Querying only one row from a one to many relationship laravel

Fatal error: Trait 'LaminasDbAdapterLaminasDbAdapterAdapterInterface' not found in /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php

Issue with laravel eloquent model property

Laravel csrf token mismatch for ajax POST Request

Creating a config file in PHP

Laravel Factory not calling callback 'afterCreating'

About Contact Privacy policy Terms and conditions