3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
8 namespace Zend\Diactoros;
10 use function preg_match_all;
11 use function urldecode;
14 * Parse a cookie header according to RFC 6265.
16 * PHP will replace special characters in cookie names, which results in other cookies not being available due to
17 * overwriting. Thus, the server request should take the cookies from the request header instead.
19 * @param string $cookieHeader A string cookie header value.
20 * @return array key/value cookie pairs.
22 function parseCookieHeader($cookieHeader)
26 (?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
29 (?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
32 )x', $cookieHeader, $matches, PREG_SET_ORDER);
36 foreach ($matches as $match) {
37 $cookies[$match['name']] = urldecode($match['value']);