/one_path/some_page.php?var1=value1&var2=value2&var3=value3
Suppose I’m given something like the above. Not just the query variable string, but the path that comes before it.
I want to parse the above string so that it creates an array that’s like
array('var1' => 'value1', 'var2' => 'value2', 'var3' => 'value3')
I can easily do this, but I’m wondering what is the ‘best’ way to do this, so the code is short and clean; I’m a bit of a perfectionist.
parse_str() is helpful once you have extracted the query string from the path. Assuming the URI is well formed, you could split them using something like this: