• 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

add " ? " in url via htaccess RewriteRule

PHP echo values of all sub keys [duplicate]

Display the default discounted price and percentage on Woocommerce products

Laravel unique validation on multiple columns

PHP Get value from JSON [duplicate]

How to create a cookie to store the timestamp of when a page is first loaded with php

MySQL upgrade causing unexpected results on simple WHERE clauses

Add bold text and line break into Laravel Notification Email

Testing subscription renewals on Stripe

Can I write PHP code across multiple lines per statement?

"Mixed content blocked" when running an HTTP AJAX operation in an HTTPS page

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

XDebug not working in VScode for php debugging

How to display MySQL table using php and edit it in a web browser

Sum array values

About Contact Privacy policy Terms and conditions