• 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

Laravel set default language not working

Which is faster php date functions or carbon?

Alert message after submitting form in PHP

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

Display the WooCommerce product price inside a custom function

Don't show recurring price for WooCommerce subscriptions worth 0$

How to prevent phpmailer sending embedded image as an attachment on Gmail?

Add 2 Webcam in one page with WebcamJS

PHP - Store information with NO database

GA4 custom event from server side, can someone tell me how i can do the following code in php?

Prestashop webservice API creating cart rules

Android Volley getParams() method not getting called for JsonObjectRequest

How to Display Data in Yajra Datatables Laravel 7?

How update php.ini on a Mac OS X Mojave?

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

About Contact Privacy policy Terms and conditions