• 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

How to get median and quartiles/percentiles of an array in JavaScript (or PHP)?

Facebook API, get page post link (PHP)

Get WooCommerce product variation attribute terms in admin products general box

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

google content api for shopping

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

PHP mail sending empty mails

How to pass security cloudflare server with php curl

How to check user Permissions using Custom Middleware in Laravel

PHP my timezone is no setting up in PHP.ini File in xampp

PHP array slice from position + attempt to return fixed number of items

Distribute array row data to make multiple new rows

Mysqli Output to a table

error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

Dynamic table in HTML using MySQL and php

About Contact Privacy policy Terms and conditions