class HeaderUtils
HTTP header utility functions.
static array | split(string $header, string $separators) Splits an HTTP header by one or more separators. | |
static array | combine(array $parts) Combines an array of arrays into one associative array. | |
static string | toString(array $assoc, string $separator) Joins an associative array into a string for use in an HTTP header. | |
static string | quote(string $s) Encodes a string as a quoted string, if necessary. | |
static string | unquote(string $s) Decodes a quoted string. |
Splits an HTTP header by one or more separators.
Example:
HeaderUtils::split("da, en-gb;q=0.8", ",;")
// => array(array('da'), array('en-gb', 'q=0.8'))
string | $header | HTTP header value |
string | $separators | List of characters to split on, ordered by precedence, e.g. ",", ";=", or ",;=" |
array | Nested array with as many levels as there are characters in $separators |
Combines an array of arrays into one associative array.
Each of the nested arrays should have one or two elements. The first value will be used as the keys in the associative array, and the second will be used as the values, or true if the nested array only contains one element. Array keys are lowercased.
Example:
HeaderUtils::combine(array(array("foo", "abc"), array("bar")))
// => array("foo" => "abc", "bar" => true)
array | $parts |
array |
Joins an associative array into a string for use in an HTTP header.
The key and value of each entry are joined with "=", and all entries are joined with the specified separator and an additional space (for readability). Values are quoted if necessary.
Example:
HeaderUtils::toString(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ",")
// => 'foo=abc, bar, baz="a b c"'
array | $assoc | |
string | $separator |
string |
Encodes a string as a quoted string, if necessary.
If a string contains characters not allowed by the "token" construct in the HTTP specification, it is backslash-escaped and enclosed in quotes to match the "quoted-string" construct.
string | $s |
string |
Decodes a quoted string.
If passed an unquoted string that matches the "token" construct (as defined in the HTTP specification), it is passed through verbatimly.
string | $s |
string |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/HeaderUtils.html