• 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

MySQL - Connection failed: No route to host

WordPress ACFNotice: get_field() - We've detected one or more calls to retrieve ACF field values before ACF has been initialized

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

Navigation idle on content download

Use Python plotly chart in PHP

CSV to PHP class properties

How to KeyBy where multiple items have the same key

Laravel insert dynamic input values with radio button

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Cannot pass null argument when using type hinting

Shortcode or PHP inside a shortcode in Wordpress

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

How can I get a div content in php

Extract house numbers from address string

Center point of multiple gps coordinates with php

About Contact Privacy policy Terms and conditions