• 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

Star rating with half star support

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

CONCAT columns with Laravel 5 eloquent

PHP, how to convert Int value to Week days

Fetch files from next cloud storage and display in Laravel website

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

PHPExcel file download using AJAX call

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

generate an Excel file using PHP

How to validate tin and cst using PHP?

how to loop through json response data using ajax jquery?

Change user role if checkout custom checkbox is checked in WooCommerce

how to identify the web server name of remote host

How to disable only_full_group_by option in Laravel

Destroy session upon refresh

About Contact Privacy policy Terms and conditions