How to Remove Query String From Url In Php? Attributes,html,javascript,Jquery How to Remove Query String From Url In Php?
Today I needed to remove the query string or parameter from the URL. I found this quick function which does exactly what i needed i.e remove query string from URL.
function remove_qs_key($url, $key) { return preg_replace(‘/(?:&|(\?))’ . $key . ‘=[^&]*(?(1)&|)?/i’, “$1″, $url); }For example, if your URL was this:
$url = http://example.com/test/index?id=55&template=view&format=pdf $key = 'format';The above function would return:
echo remove_qs_key($url, $key); //output: http://example.com/test/index?id=55&template=viewAll I needed to do was provide the URL and the key to remove -- so easy and simple :)
Thanks to http://davidwalsh.name/php-remove-variable
0 Response to "How to Remove Query String From Url In Php?"
Posting Komentar