• 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

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Laravel Carbon throws error The format separator does not match

getting error while enter Command => php artisan route:list

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Star and Half Star Rating in Laravel

Laravel no logout option from menu after successfull login

PHP/HTML: Creating A SubMenu

how to get value from array in laravel

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

Remove product downloads section in woocommerce email notifications

How to validate tin and cst using PHP?

WordPress ACFNotice: get_field() - We've detected one or more calls to retrieve ACF field values before ACF has been initialized

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

WooCommerce: Add/display Product or Variation custom field everywhere

PHP - Check if string contains words longer than 4 characters, then include "+ *", and for those shorter than 4 characters include only "*"

About Contact Privacy policy Terms and conditions