SimplePie_Misc::parse_str PHP Method

parse_str() public method

Returns an associative array of name/value pairs, where the value is an array of values that have used the same name
public parse_str ( string $str ) : array
$str string The input string.
return array
    function parse_str($str)
    {
        $return = array();
        $str = explode('&', $str);
        foreach ($str as $section) {
            if (strpos($section, '=') !== false) {
                list($name, $value) = explode('=', $section, 2);
                $return[urldecode($name)][] = urldecode($value);
            } else {
                $return[urldecode($section)][] = null;
            }
        }
        return $return;
    }

Usage Example

 public function __construct($mysql_location, $name, $extension)
 {
     $host = $mysql_location->get_host();
     if (stripos($host, 'unix(') === 0 && substr($host, -1) === ')') {
         $server = ':' . substr($host, 5, -1);
     } else {
         $server = $host;
         if ($mysql_location->get_port() !== null) {
             $server .= ':' . $mysql_location->get_port();
         }
     }
     if (strpos($mysql_location->get_userinfo(), ':') !== false) {
         list($username, $password) = explode(':', $mysql_location->get_userinfo(), 2);
     } else {
         $username = $mysql_location->get_userinfo();
         $password = null;
     }
     if ($this->mysql = mysql_connect($server, $username, $password)) {
         $this->id = $name . $extension;
         $this->options = SimplePie_Misc::parse_str($mysql_location->get_query());
         if (!isset($this->options['prefix'][0])) {
             $this->options['prefix'][0] = '';
         }
         if (mysql_select_db(ltrim($mysql_location->get_path(), '/')) && mysql_query('SET NAMES utf8') && ($query = mysql_unbuffered_query('SHOW TABLES'))) {
             $db = array();
             while ($row = mysql_fetch_row($query)) {
                 $db[] = $row[0];
             }
             if (!in_array($this->options['prefix'][0] . 'cache_data', $db)) {
                 if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))')) {
                     $this->mysql = null;
                 }
             }
             if (!in_array($this->options['prefix'][0] . 'items', $db)) {
                 if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))')) {
                     $this->mysql = null;
                 }
             }
         } else {
             $this->mysql = null;
         }
     }
 }