/** * Parses a string containing INI formatted data. * * Returns an array with the parsed content of the string or null on failure. * This function is case-sensitive when reading sections and keys. * * @param string String containing INI data. * @return array Array with the data or null on failure * @author Justin Frim <*****@*****.**> */ public function parseString($str) { $array1 = Strings::toTrimmedArray($str); $array2 = array(); // Reset comment etc. $this->comment = array(); $section = ''; $firstElementFound = false; foreach ($array1 as $line) { if (empty($line) == true) { // If line is empty jump to next line continue; } // Read the first char of the line to analyse type (section, comment, element) $firstchar = substr($line, 0, 1); if ($firstchar == $this->commentChar) { // It's a comment if ($firstElementFound == false) { // The comment belongs to the heading comment $this->comment[] = trim(substr($line, 1)); } } else { // It's not a comment. // We have found the first element (section or key/value). // No more comments can be read, stop it... $firstElementFound = true; //It's an entry (not a comment and not a blank line) if ($firstchar == '[' && substr($line, -1, 1) == ']') { //It's a section $section = substr($line, 1, -1); } else { //It's a key... $delimiter = strpos($line, '='); if ($delimiter > 0) { //...with a value list($key, $value) = explode('=', $line, 2); $key = trim($key); $value = trim($value); if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); $value = str_replace('\\r', "\r", $value); $value = str_replace('\\n', "\n", $value); } if ($this->mode == self::BINARY) { $value = stripcslashes($value); } } else { //...without a value $key = $line; $value = ''; } if (empty($section)) { $array2[$key] = $value; } else { $array2[$section][$key] = $value; } } } } return $array2; }
/** * Performs one or more raw queries on the database. * * Executes one or multiple queries which are concatenated by a semicolon and a linebreak. * You get back an array with all the results in the order of the queries. * Comments are stripped. * * @param string Queries */ public function multiQuery($query) { $results = array(); $lines = Strings::toTrimmedArray($query); $query = ''; foreach ($lines as $line) { $comment = substr($line, 0, 2); if ($comment == '--' || $comment == '//' || strlen($line) <= 10) { continue; } $query .= $line."\n"; } $lines = explode(";\n", $query); foreach ($lines as $key => $line) { if (strlen($line) > 10) { unset($result); $result = $this->rawQuery($line); $results[$key] = array(); if ($this->isResultSet($result) && $this->numRows($result) > 0) { while ($row = $this->fetchAssoc($result)) { $results[$key][] = $row; } } } } return $s; }