• 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 5 controller sending JSON integer as string

Substitute integers and dots with regex [duplicate]

How to validate tin and cst using PHP?

Get sum of arrays inside array

Get WooCommerce product variation attribute terms in admin products general box

(Laravel) How to delete multiple models including optional relationships?

run a query using EXECUTE BLOCK to prepair a column for an unique-Index

how do i retrieve and display the alt text of an image in wordpress?

WooCommerce - unset "<product> removed notice…" on cart page

Adding reCAPTCHA v2 into my PHP file

Issue saving card for customer

Transform array, set each array element with parent key php

PHP: How to solve ob_start() in combination imagepng() issue?

How do I call Validator from a namespace with an already existing Validator class

(Cache::lock()) -> get() -- Under what conditions does it return false?

About Contact Privacy policy Terms and conditions