Parse header string

@param string $headerString header block

@return array
976465
public static function parseHeaders($headerString)
	{
		$headers = explode("\n", $headerString);
		$keys = array_keys($headers);
		$regexReturnCode = '/^\S+\s+(\d+)\s?(.*)/';
		$regexHeader = '/^(.*?):\s*(.*)$/';
		$headers['Return-Code'] = preg_match($regexReturnCode, $headerString, $matches)
			? $matches[1]
			: 200;
		foreach ($keys as $k) {
			$v = trim($headers[$k]);
			unset($headers[$k]);
			if (preg_match($regexHeader, $v, $matches)) {
				$k = $matches[1];
				$k = preg_replace_callback('/(^|-)(.?)/', function ($matches) {
					return $matches[1].strtoupper($matches[2]);
				}, $k);
				$v = trim($matches[2]);
				if (isset($headers[$k])) {
					if (!is_array($headers[$k])) {
						$headers[$k] = array($headers[$k]);
					}
					$headers[$k][] = $v;
				} else {
					$headers[$k] = $v;
				}
			} elseif (preg_match($regexReturnCode, $v, $matches)) {
				$headers['Return-Code'] = $matches[1];
			}
		}
		return $headers;
	}
1326951
function parse(headers) {
    var output = {}, i, p, k, v;
    headers = headers || '';
    headers = headers.replace('\r', '');
    headers = headers.split('\n');
    for(i = 0;i < headers.length;i++) {
      p = headers[i].indexOf(':');
      k = headers[i].substr(0, p);
      v = headers[i].substr(p + 1);
      if(k && v) {
        k = k.replace(/^\s+/, '').replace(/\s+$/, '');
        v = v.replace(/^\s+/, '').replace(/\s+$/, '');
        output[k.toLowerCase()] = v;
      }
    }
    return output;
  }
668397
public static function xml2array($xmlstring)
    {
        $result = [];
        self::normalizeSimpleXML(simplexml_load_string($xmlstring, null, LIBXML_NOCDATA), $result);

        return $result;
    }
324574
protected function parseAcceptHeader(?string $headerValue): array
	{
		$groupedAccepts = [];

		if(empty($headerValue))
		{
			return $groupedAccepts;
		}

		// Collect acceptable values

		foreach(explode(',', $headerValue) as $accept)
		{
			$quality = 1;

			if(strpos($accept, ';'))
			{
				// We have a quality so we need to split some more

				[$accept, $quality] = explode(';', $accept, 2);

				// Strip the "q=" part so that we're left with only the numeric value

				$quality = substr(trim($quality), 2);
			}

			$groupedAccepts[$quality][] = trim($accept);
		}

		// Sort in descending order of preference

		krsort($groupedAccepts);

		// Flatten array and return it

		return array_merge(...array_values($groupedAccepts));
	}
1178846
private function parseHeader($header) {
        if(!empty($header)) {
            $pos = strpos($header, ": ");

            if(false !== $pos) {
                $name = substr($header,0,$pos);
                $value = substr($header,$pos+2);

                $this->headers[$name] = $value;
            }
        }
    }
695361
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');
        $atomLinkXml = simplexml_load_string($xmlString);
        $attributes = $atomLinkXml->attributes();

        if (!empty($attributes['href'])) {
            $this->href = (string) $attributes['href'];
        }

        if (!empty($attributes['rel'])) {
            $this->rel = (string) $attributes['rel'];
        }

        if (!empty($attributes['type'])) {
            $this->type = (string) $attributes['type'];
        }

        if (!empty($attributes['hreflang'])) {
            $this->hreflang = (string) $attributes['hreflang'];
        }

        if (!empty($attributes['title'])) {
            $this->title = (string) $attributes['title'];
        }

        if (!empty($attributes['length'])) {
            $this->length = (int) $attributes['length'];
        }

        $undefinedContent = (string) $atomLinkXml;
        if (empty($undefinedContent)) {
            $this->undefinedContent = null;
        } else {
            $this->undefinedContent = (string) $atomLinkXml;
        }
    }
1135258
public function parseHeaders()
    {
        $headers = '';
        foreach ($this->headers as $key => $value) {
            if ($key !== 'to') {
                $headers .= $key . ': ' . $this->getHeaderLine($key) . "\r\n";
            }
        }

        return $headers;
    }
61277
public function processConvert($xmlString)
    {
        $result = [];

        if(true === $this->isXml($xmlString))
        {
            $iterator = new SimpleXmlIterator($xmlString);

            $result = $this->getArrayFromXml($iterator);
        }

        return $result;
    }
714810
protected function parseBooleanShortcut($propertyString)
    {
        $value = true;
        $key = $propertyString;

        if ($propertyString[0] == '!') {
            $value = false;
            $key = mb_substr($propertyString, 1);
        }

        return [$key, $value];
    }
184572
private function parseHeaders($headerContent)
    {
        $headers = [];
        $headerParts = preg_split('/\\R/s', $headerContent, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($headerParts as $headerPart) {
            if (strpos($headerPart, ':') === false) {
                continue;
            }

            [$headerName, $headerValue] = explode(':', $headerPart, 2);
            $headerName = strtolower(trim($headerName));
            $headerValue = trim($headerValue);

            if (strpos($headerValue, ';') === false) {
                $headers[$headerName] = $headerValue;
            } else {
                $headers[$headerName] = [];
                foreach (explode(';', $headerValue) as $part) {
                    $part = trim($part);
                    if (strpos($part, '=') === false) {
                        $headers[$headerName][] = $part;
                    } else {
                        [$name, $value] = explode('=', $part, 2);
                        $name = strtolower(trim($name));
                        $value = trim(trim($value), '"');
                        $headers[$headerName][$name] = $value;
                    }
                }
            }
        }

        return $headers;
    }
978137
private function parseHeaders(array $headers)
    {
        $indexes = [];
        $metas   = [];

        foreach ($headers as $key => $value) {
            $key = strtolower($key);

            if (strpos($key, 'x-riak-index-') === 0) {
                $name  = substr($key, 13);
                $value = isset($indexes[$name])
                    ? array_merge($indexes[$name], $value)
                    : $value;

                $indexes[$name] = $value;
            }

            if (strpos($key, 'x-riak-meta-') === 0) {
                $name  = strtolower(substr($key, 12));
                $value = is_array($value)
                    ? reset($value)
                    : $value;

                $metas[$name] = $value;
            }
        }

        return [
            'indexes' => $indexes,
            'metas'   => $metas
        ];
    }
1352656
public static function parse_headers($headers)
    {
        $a_headers = array();
        $headers   = preg_replace('/\r?\n(\t| )+/', ' ', $headers);
        $lines     = explode("\n", $headers);
        $count     = count($lines);

        for ($i=0; $i<$count; $i++) {
            if ($p = strpos($lines[$i], ': ')) {
                $field = strtolower(substr($lines[$i], 0, $p));
                $value = trim(substr($lines[$i], $p+1));
                if (!empty($value)) {
                    $a_headers[$field] = $value;
                }
            }
        }

        return $a_headers;
    }
582302
public static function parseHeaderValue(string $value): array
    {
        $parts = \explode(';', $value);
        $type = \trim($parts[0]);
        unset($parts[0]);

        $parameters = [];
        foreach ($parts as $part) {
            [$k, $v] = \explode('=', $part, 2);

            $key = \strtolower(\trim($k));
            $parameters[$key] = \trim($v, ' "');
        }

        return [$type, $parameters];
    }
662976
public function getValues(string $rawString)
    {
        $regExp = $this->getStrRegExp();
        $params = $this->getParameters();
        $matches = [];

        preg_match_all($regExp, $rawString, $matches);
        array_shift($matches);

        $map = function ($match) {
            return isset($match[0]) ? $match[0] : null;
        };

        return array_combine($params, array_map($map, $matches));
    }
597773
public static function parse($headers)
    {
        if (is_string($headers)) {
            $headers = explode("\r\n\r\n", trim($headers));

            return explode("\r\n", end($headers));
        }

        $parsedHeaders = [];

        foreach ($headers as $name => $value) {
            $value = HeadersNormalizer::normalizeHeaderValue($value);

            if (is_int($name)) {
                if (strpos($value, 'HTTP/') === 0) {
                    $parsedHeaders = [$value];
                } else {
                    $parsedHeaders[] = $value;
                }
            } else {
                $parsedHeaders[] = $name.': '.$value;
            }
        }

        return $parsedHeaders;
    }
1364999
private static function parse(string $headers): array
    {
        $header  = [];
        $matches = [];
        preg_match_all(
                '=^(.[^: ]+): ([^\r\n]*)=m',
                $headers,
                $matches,
                PREG_SET_ORDER
        );
        foreach ($matches as $line) {
            $header[$line[1]] = $line[2];
        }

        return $header;
    }
1005827
private function parseStr($dataString)
    {
        $data = [];
        parse_str($dataString, $data);

        $this->setContent($dataString);
        if(is_array($data)) $this->setData($data);

        $this->emit('end');
    }