Written by Sean Behan on Mon Dec 04th 2017

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']

Tagged with..
#query string #php #urls #snippets

Just finishing up brewing up some fresh ground comments...