• 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

Invalid value in field "itemtype" in Google Search Console

How to use PHPCBF to fix one issue at a time?

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Clients authentication and user authentication with laravel

500 (Internal Server Error) with Laravel & Docker [duplicate]

Comma separated list from array with "and" before last element

How to get values inside <![CDATA[values]] > using php DOM?

printing all running session variable in laravel 5.1

Search for array row with specific column value and return another value from qualifying row

Target class controller does not exist - Laravel 8

How to display table header in every page using FPDF library?

How to update array value in Laravel

browsersync doesn't work with XAMPP

Custom add to cart button URL for specific product in WooCommerce?

how to remove %20 in the url in php

About Contact Privacy policy Terms and conditions