Skip to content

Message: getHeader Example

Terry L edited this page Jun 20, 2020 · 3 revisions
Clone this wiki locally

Shieldon\Psr7\Message

getHeader($name)

Retrieves a message header value by the given case-insensitive name.

  • param string name * Case-insensitive header field name.
  • return array An array of string values as provided for the given. Return empty array if the header dosn't exist.

Example:

$useragent = $this->message->getHeader('user-agent');

print(print_r($useragent, true));

/* Outputs:

    Array
    (
        [0] => Mozilla/5.0 (Windows NT 10.0; Win64; x64)
    )

*/

$useragent = $this->message->getHeader('does-not-exist');

print(print_r($useragent, true));

/* Outputs:

    Array()

*/