Tuesday, March 31, 2009

Remove Query String Using Regular Expressions

You can use this code to remove query string from URL.

<?php
$url = "http://www.testDomain.com/testPage.php?q1=queryString1&q2=queryString2";

$search = '|(\.php)(.*)|i';
$replace = '${1}';

echo preg_replace( $search, $replace, $url );

?>

No comments:

Post a Comment