• 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

How to disable only_full_group_by option in Laravel

generating a random code in php?

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Facebook API, get page post link (PHP)

Mobile browsers are adding .html to filename on download

Add custom text under order details on WooCommerce My account view order pages

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

Group data in a multidimensional array based on two columns

How to validate Envato Purchase Code in PHP

How to set dynamic `home` and `siteurl` in WordPress?

How to reset Laravel AuthManager/guards in between API calls in tests?

Creating command to backup MySql database in Laravel

nginx err_connection_refused, can anyone help me?

PHP 8.1: strftime() is deprecated

How to test a php login connected to a mysql db through xampp?

About Contact Privacy policy Terms and conditions