private function parseHeaders($str) {

		if(false === is_string($str)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($str)), E_USER_ERROR);
		}
		
		$headers = [];
		$status  = [];

		foreach(explode("\n", $str) as $header) {
			
			if(preg_match('/(:)/is', $header)) {
				list($key, $value) = preg_split('/(:)/is', $header, 2);
			}
			else {
				$key = $header;
			}

			if(trim($key) !== '') {

				if(preg_match('/(https?\/[0-9]\.[0-9])/i', $key, $http)) {

					$status['code'] = null;

					if(preg_match('/([0-9]+)/', ltrim($key, $http[0]), $code)) {
						$status['code'] = $code[0];
					}

					$status['protocol'] = $http[0];
					$status['status'] 	= trim($key);
					$status['text'] 	= trim(ltrim(trim(ltrim($key, $status['protocol'])), $status['code']));
					
				}
				else {
					$headers[strtolower($key)] = trim($value);
				}
			}
		}

		return ['headers' => $headers, 'status' => $status];
	}
private function parseHeaders($str) {

		if(false === is_string($str)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($str)), E_USER_ERROR);
		}
		
		$headers = [];
		$status  = [];

		foreach(explode("\n", $str) as $header) {
			
			if(preg_match('/(:)/is', $header)) {
				list($key, $value) = preg_split('/(:)/is', $header, 2);
			}
			else {
				$key = $header;
			}

			if(trim($key) !== '') {

				if(preg_match('/(https?\/[0-9]\.[0-9])/i', $key, $http)) {

					$status['code'] = null;

					if(preg_match('/([0-9]+)/', ltrim($key, $http[0]), $code)) {
						$status['code'] = $code[0];
					}

					$status['protocol'] = $http[0];
					$status['status'] 	= trim($key);
					$status['text'] 	= trim(ltrim(trim(ltrim($key, $status['protocol'])), $status['code']));
					
				}
				else {
					$headers[strtolower($key)] = trim($value);
				}
			}
		}

		return ['headers' => $headers, 'status' => $status];
	}
private function parseHeaders ( $ str ) { if ( false === is_string ( $ str ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ str ) ) , E_USER_ERROR ) ; } $ headers = [ ] ; $ status = [ ] ; foreach ( explode ( "\n" , $ str ) as $ header ) { if ( preg_match ( '/(:)/is' , $ header ) ) { list ( $ key , $ value ) = preg_split ( '/(:)/is' , $ header , 2 ) ; } else { $ key = $ header ; } if ( trim ( $ key ) !== '' ) { if ( preg_match ( '/(https?\/[0-9]\.[0-9])/i' , $ key , $ http ) ) { $ status [ 'code' ] = null ; if ( preg_match ( '/([0-9]+)/' , ltrim ( $ key , $ http [ 0 ] ) , $ code ) ) { $ status [ 'code' ] = $ code [ 0 ] ; } $ status [ 'protocol' ] = $ http [ 0 ] ; $ status [ 'status' ] = trim ( $ key ) ; $ status [ 'text' ] = trim ( ltrim ( trim ( ltrim ( $ key , $ status [ 'protocol' ] ) ) , $ status [ 'code' ] ) ) ; } else { $ headers [ strtolower ( $ key ) ] = trim ( $ value ) ; } } } return [ 'headers' => $ headers , 'status' => $ status ] ; }
Parses headers and forms it into an Array
@param string $str
@return array
Parses headers and forms it into an Array