phparraysquery-stringkey-valuestring-parsing

How to parse a querystring formatted string?


I have a string category=45&format=1 that I want to convert into a key=value array.

Does anyone know if there is a quick way of doing this without having to write a function that explode's the & and then the =?


Solution

  • Since you're dealing with the URL query format: parse_str

    parse_str('category=45&format=1', $array);
    

    http://php.net/parse_str