• 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 check user Permissions using Custom Middleware in Laravel

Create tags in laravel post publishing

Reorder attribute dropdown terms in Woocommerce single variable products

Laravel Route issues with Route order in web.php

LARAVEL: How to fetch id dynamically in a query builder?

Can't exclude directories from .htaccess mobile redirect?

XSS attack still works despite htmlspecialchars() doing its work

Yii2: How do I debug console commands?

Laravel Factory not calling callback 'afterCreating'

Transfer data between JavaScript and PHP through JSON

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: no such host known

Transpose multidimensional array and join values with commas

onKeyUp event calculation not working on the following rows from php generated forms except the first one

How to get Laravel's CSRF Token from Another Website?

How can i call a function that executes an fpdf based on the choice of a form selector?

About Contact Privacy policy Terms and conditions