Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HeaderUtils.php

function HeaderUtils::split

Splits an HTTP header by one or more separators.

Example:

HeaderUtils::split('da, en-gb;q=0.8', ',;') # returns [['da'], ['en-gb', 'q=0.8']]

Parameters

string $separators List of characters to split on, ordered by: precedence, e.g. ',', ';=', or ',;='

Return value

array Nested array with as many levels as there are characters in $separators

6 calls to HeaderUtils::split()
AcceptHeader::fromString in vendor/symfony/http-foundation/AcceptHeader.php
Builds an AcceptHeader instance from a string.
AcceptHeaderItem::fromString in vendor/symfony/http-foundation/AcceptHeaderItem.php
Builds an AcceptHeaderInstance instance from a string.
BinaryFileResponse::prepare in vendor/symfony/http-foundation/BinaryFileResponse.php
Prepares the Response before it is sent to the client.
Cookie::fromString in vendor/symfony/http-foundation/Cookie.php
Creates cookie from raw header string.
HeaderBag::parseCacheControl in vendor/symfony/http-foundation/HeaderBag.php
Parses a Cache-Control HTTP header.

... See full list

File

vendor/symfony/http-foundation/HeaderUtils.php, line 45

Class

HeaderUtils
HTTP header utility functions.

Namespace

Symfony\Component\HttpFoundation

Code

public static function split(string $header, string $separators) : array {
    if ('' === $separators) {
        throw new \InvalidArgumentException('At least one separator must be specified.');
    }
    $quotedSeparators = preg_quote($separators, '/');
    preg_match_all('
            /
                (?!\\s)
                    (?:
                        # quoted-string
                        "(?:[^"\\\\]|\\\\.)*(?:"|\\\\|$)
                    |
                        # token
                        [^"' . $quotedSeparators . ']+
                    )+
                (?<!\\s)
            |
                # separator
                \\s*
                (?<separator>[' . $quotedSeparators . '])
                \\s*
            /x', trim($header), $matches, \PREG_SET_ORDER);
    return self::groupParts($matches, $separators);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal