• 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

backup files to google drive using PHP

How to install ZeroMQ for PHP on an Alpine Linux container?

User pool client {id}does not exist

Android Volley getParams() method not getting called for JsonObjectRequest

Laravel SQL query midnight time not showing

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

Vimeo API: how to save a vimeo into a subfolder?

Get number of working days between two dates in PHP [duplicate]

Statement that checks whether a URL contains a particular path?

Attempted to call an undefined method named "get" of class "MailController"

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

phpseclib 2.0 can not use Composer to create autoload

500 Internal Server Error on Ajax request. Not sure the origin of the problem

How to pass data to all views in Laravel 5?

Xdebug in Laravel is not working with VSCode

About Contact Privacy policy Terms and conditions