• 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

phpunit - testing is painfully slow

how to create html table in php

Timber: Single post pagination does not work (wp_link_pages)

Star rating with half star support

Mysqli Output to a table

correct PHP headers for pdf file download

Extract string between first whitespace and last whitespace in php

PHP - Store information with NO database

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

Fatal error: Array callback has to contain indices 0 and 1

Laravel Get Days In Month From Month Number?

How can I get a div content in php

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

Custom post type single page not working

Confirm Leave on External Links in Wordpress

About Contact Privacy policy Terms and conditions