Return to Snippet

Revision: 56258
at March 18, 2012 17:24 by anagaiyahoocom


Initial Code
/**
        * Parse out url query string into an associative array
        *
        * $qry can be any valid url or just the query string portion.
        * Will return false if no valid querystring found
        *
        * @param $qry String
        * @return Array
        */
        function queryToArray($qry)
        {
                $result = array();
                //string must contain at least one = and cannot be in first position
                if(strpos($qry,'=')) {

                 if(strpos($qry,'?')!==false) {
                   $q = parse_url($qry);
                   $qry = $q['query'];
                  }
                }else {
                        return false;
                }

                foreach (explode('&', $qry) as $couple) {
                        list ($key, $val) = explode('=', $couple);
                        $result[$key] = $val;
                }

                return empty($result) ? false : $result;

        }

Initial URL

                                

Initial Description
This will take an url or just the querystring portion and break it out into an array

Initial Title
Parse url querystring into an array

Initial Tags

                                

Initial Language
PHP