Zebra_cURL::_parse_headers PHP 메소드

_parse_headers() 개인적인 메소드

It parses a string containing one or more HTTP headers and returns an array of headers where each entry also contains an associative array of name => value for each row of data in the respective header.
private _parse_headers ( string $headers ) : mixed
$headers string A string containing one or more HTTP headers, where multiple headers are separated by a blank line. @return mixed Returns an array of headers where each entry also contains an associative array of name => value for each row of data in the respective header. If CURLOPT_HEADER is set to FALSE or 0, this method will return an empty string. @access private
리턴 mixed
    private function _parse_headers($headers)
    {
        $result = array();
        // if we have nothing to work with
        if ($headers != '') {
            // split multiple headers by blank lines
            $headers = preg_split('/^\\s*$/m', trim($headers));
            // iterate through the headers
            foreach ($headers as $index => $header) {
                $arguments_count = func_num_args();
                // get all the lines in the header
                // lines in headers look like [name] : [value]
                // also, the first line, the status, does not have a name, so we add the name now
                preg_match_all('/^(.*?)\\:\\s(.*)$/m', ($arguments_count == 2 ? 'Request Method: ' : 'Status: ') . trim($header), $matches);
                // save results
                foreach ($matches[0] as $key => $value) {
                    $result[$index][$matches[1][$key]] = trim($matches[2][$key]);
                }
            }
        }
        // return headers as an array
        return $result;
    }