• 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

Change the alert text on add to cart action without selected variation in Woocommerce

How to redirect to another page and call a Function there on Angular ng-click

oauth-private.key does not exist or is not readable

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

Error when uploading certain .png files "Interlace handling should be turned on when using png_read_image"

virtctl works when executed via command line but not from php exec()

Problems getting instance of UploadedFile in Yii2

Convert PHP array into HTML tag attributes separated by spaces

Generate random username based on full name php

array_key_exists(): The first argument should be either a string or an integer

PHP Find Array Index value in multi-line array

Laravel Nova, route not found

Group rows by column and sum another column within groups [duplicate]

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Hide email address with stars (*)

About Contact Privacy policy Terms and conditions