· 1 min read

How to Parse Query Strings in PHP

Here is a quick snippet for parsing query strings in PHP. You can use the parse_url and parse_str methods. parse_str will create a variable for you populated with results.

$url = "http://www.seanbehan.com/path/?param=key";
parse_str(parse_url(trim($url))['query'], $qs);
echo $qs;
// returns ['param' => 'key']

Comments

Leave a comment