• 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 make autocomplete work in foreach php loop? (vscode, intellisense)

Using Associative arrays

shell errors running php exec

Parsing JSON File to array in PHP

Invalid value in field "itemtype" in Google Search Console

Can't find vendor/autoload.php for Ratchet

Adding reCAPTCHA v2 into my PHP file

WordPress - Dynamically add user ID to the end of a URL

Laravel whole batch is cancelled if one Job fails

NGINX: connect() to unix:/var/run/php7.2-fpm.sock failed (2: No such file or directory)

How to create a scheduler application in php

PHP -> Next nearest date defined by array of days in week

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

Check if user online laravel

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

About Contact Privacy policy Terms and conditions