This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

How to Remove Query String From Url In Php?

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=view 
All 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

Contact

Nama

Email *

Pesan *