src/Net.php
public static function getHeaderValue($key = 'Content-Type', $headers = array())
	{
		$value = null;
		if (empty($headers)) {
			// no headers passed... determine from sent
			if (function_exists('headers_list')) {
				$headers = headers_list();
			} elseif (function_exists('apache_response_headers')) {
				// apache_response_headers is somewhat worthless.... must flush the output first via ob_end_flush
				$headers = apache_response_headers();
				if (!headers_sent()) {
					// $this->debug->warn('headers not yet sent.. unable to determine complete list');
					// $this->debug->log('headers', $headers);
				}
			} else {
				// $this->debug->warn('unable to determine sent headers');
			}
		}
		if ($headers) {
			if (is_string($headers)) {
				$headers = explode("\n", $headers);
			}
			$arrayUtil = new ArrayUtil();
			if ($arrayUtil->isHash($headers)) {
				if (isset($headers[$key])) {
					$value = $headers[$key];
				}
			} else {
				foreach ($headers as $header) {
					if (preg_match('/^'.$key.':\s*([^;]*)/i', $header, $matches)) {
						$value = $matches[1];
						break;
					}
				}
			}
		}
		if (is_null($value) && $key == 'Content-Type') {
			$value = ini_get('default_mimetype');
		}
		// $this->debug->log('value', $value);
		// $this->debug->groupEnd();
		return $value;
	}
public static function getHeaderValue($key = 'Content-Type', $headers = array())
	{
		$value = null;
		if (empty($headers)) {
			// no headers passed... determine from sent
			if (function_exists('headers_list')) {
				$headers = headers_list();
			} elseif (function_exists('apache_response_headers')) {
				// apache_response_headers is somewhat worthless.... must flush the output first via ob_end_flush
				$headers = apache_response_headers();
				if (!headers_sent()) {
					// $this->debug->warn('headers not yet sent.. unable to determine complete list');
					// $this->debug->log('headers', $headers);
				}
			} else {
				// $this->debug->warn('unable to determine sent headers');
			}
		}
		if ($headers) {
			if (is_string($headers)) {
				$headers = explode("\n", $headers);
			}
			$arrayUtil = new ArrayUtil();
			if ($arrayUtil->isHash($headers)) {
				if (isset($headers[$key])) {
					$value = $headers[$key];
				}
			} else {
				foreach ($headers as $header) {
					if (preg_match('/^'.$key.':\s*([^;]*)/i', $header, $matches)) {
						$value = $matches[1];
						break;
					}
				}
			}
		}
		if (is_null($value) && $key == 'Content-Type') {
			$value = ini_get('default_mimetype');
		}
		// $this->debug->log('value', $value);
		// $this->debug->groupEnd();
		return $value;
	}
public static function getHeaderValue ( $ key = 'Content-Type' , $ headers = array ( ) ) { $ value = null ; if ( empty ( $ headers ) ) { // no headers passed... determine from sent if ( function_exists ( 'headers_list' ) ) { $ headers = headers_list ( ) ; } elseif ( function_exists ( 'apache_response_headers' ) ) { // apache_response_headers is somewhat worthless.... must flush the output first via ob_end_flush $ headers = apache_response_headers ( ) ; if ( ! headers_sent ( ) ) { // $this->debug->warn('headers not yet sent.. unable to determine complete list'); // $this->debug->log('headers', $headers); } } else { // $this->debug->warn('unable to determine sent headers'); } } if ( $ headers ) { if ( is_string ( $ headers ) ) { $ headers = explode ( "\n" , $ headers ) ; } $ arrayUtil = new ArrayUtil ( ) ; if ( $ arrayUtil -> isHash ( $ headers ) ) { if ( isset ( $ headers [ $ key ] ) ) { $ value = $ headers [ $ key ] ; } } else { foreach ( $ headers as $ header ) { if ( preg_match ( '/^' . $ key . ':\s*([^;]*)/i' , $ header , $ matches ) ) { $ value = $ matches [ 1 ] ; break ; } } } } if ( is_null ( $ value ) && $ key == 'Content-Type' ) { $ value = ini_get ( 'default_mimetype' ) ; } // $this->debug->log('value', $value); // $this->debug->groupEnd(); return $ value ; }
Get header value

@param string       $key     Defaults to 'Content-Type'
@param array|string $headers =array() Defaults to sent headers, can be string, numeric array, or key/value array

@return string
Get header value