public function deserializeHeaders($flat_headers) { $tmp_headers = Strings::toArray($flat_headers); if (preg_match("~HTTP/(\d\.\d)\s+(\d+).*~i", $tmp_headers[0], $matches) > 0) { $this->setHeader('Protocol-Version', $matches[1]); $this->setHeader('Status', $matches[2]); } array_shift($tmp_headers); foreach($tmp_headers as $value) { $pos = strpos($value, ':'); if ($pos !== false) { $key = substr($value, 0, $pos); $value = trim(substr($value, $pos+1)); if (strtolower($key) == 'set-cookie') { $this->cookiesHeaders[] = $value; } else { $this->setHeader($key, $value); } } } }
/** * Parses a string containing csv formatted data. * * Returns a multidimensional array with the parsed content of the string or null on failure. * If the usage of headers are enabled the header values are used as keys for the array. * * @param string String containing csv data. * @return array Array with the data or null on failure */ public function parseString($str) { if (!is_string($str)) { return null; } $lines = Strings::toArray($str); $data = array(); $header = array(); $numLine = ($this->headers == true) ? -1 : 0; foreach($lines as $line) { $cols = $this->parseLine($line); if ($numLine >= 0) { $data[$numLine] = array(); } $numCol = 0; foreach($cols as $col) { if($numLine == -1 && $this->headers == true) { $header[$numCol] = $col; } elseif($numLine >= 0 && $this->headers == true) { $data[$numLine][$header[$numCol]] = $this->unescape($col); } else { $data[$numLine][$numCol] = $this->unescape($col); } $numCol++; } $numLine++; } return $data; }