Parse string as a query string
There has been an odd occasion in the past where I have used a string (Note: not the query string) in order to form a settings class in some way or another. I didn’t realise that there was a built in PHP function for this, and is only through reading through most of the PHP string functions that I came across it (and many other interesting functions).
The times of doing this are long gone (Am using the query string here just for clarity):
- <?php
- foreach (explode('&', $_SERVER['QUERY_STRING']) as $chunk) {
- $chunk = explode('=', $chunk);
- $variables[$chunk[0]] = $chunk[1];
- }
And I am now saying “hello” to this:
- <?php
- $variables = parse_str($_SERVER['QUERY_STRING']);

1 John wrote
14th May, 2008
Cool. I wasnt aware of parse_string(). I seem to remember doing something similar to you, but from more of a configuration file.