• 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

Boolean assignment operators in PHP

Applying programmatically a coupon to an Order in WooCommerce3

Having trouble with PDO queries (Notice: Undefined index)

enable Apache http Authorization header

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

Array to string conversion

Cant seem to get the Pagination to work on my WooCommerce REST API application?

php mysql + create a friend request system

Laravel query builder binding parameters more than once

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

PHP password_verify

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Adding custom body class to the custom archive pages

Unsure why I am getting: Number of variables doesn't match number of parameters in prepared statement

Additional price based on cart item count in WooCommerce

About Contact Privacy policy Terms and conditions