• 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

MOODLE: What does it mean to aggregate h5p assets?

How to Create WooCommerce Subscription Product via. REST API?

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

How to set time with DateTime modify?

How to loop a tree array with unknown depth and get array blocks?

enable Apache http Authorization header

How to give apache permission to write to home directory?

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

Normalize DateInterval in PHP

Ajax GET request fails in laravel 8

Custom post type single page not working

Display a product custom field only in WooCommerce Admin single orders

Check if a string contain multiple specific words

json_encode turns array into an object

PHP Slim Framework request using withAttribute error

About Contact Privacy policy Terms and conditions