Oihana PHP

parseParameters.php

Table of Contents

Functions

parseParameters()  : array<string, string>
Parses a parameter string of the form `key=value` pairs joined by an item separator, into an associative array.

Functions

parseParameters()

Parses a parameter string of the form `key=value` pairs joined by an item separator, into an associative array.

parseParameters(string $input[, string $itemSep = ';' ][, string $kvSep = '=' ][, bool $lowercaseKeys = false ]) : array<string, string>

Each segment is split by the first occurrence of $kvSep. Segments with no $kvSep are treated as bare tokens whose value is ''. Quoted values are unquoted with [[unquote]] (no escape decoding).

Splitting respects quoted regions via [[splitOutsideQuotes]], so a separator appearing inside "…" (or any recognised quote pair) does not break parsing.

Generic by design — no normalisation, no header-specific rules. For RFC 7230 header parameters, wrap this with $lowercaseKeys = true.

Parameters
$input : string

The string to parse.

$itemSep : string = ';'

Separator between pairs (default ;).

$kvSep : string = '='

Separator between key and value (default =).

$lowercaseKeys : bool = false

Whether to lowercase keys (default false).

Tags
example
parseParameters('a=1; b=2');
// ['a' => '1', 'b' => '2']

parseParameters('charset="utf-8"; boundary=xyz');
// ['charset' => 'utf-8', 'boundary' => 'xyz']

parseParameters('Charset=UTF-8; Boundary=xyz', ';', '=', true);
// ['charset' => 'UTF-8', 'boundary' => 'xyz']

parseParameters('flag; key=value');
// ['flag' => '', 'key' => 'value']

parseParameters('key="a;b"; other=c');
// ['key' => 'a;b', 'other' => 'c']
author

Marc Alcaraz

since
1.0.8
see
splitOutsideQuotes()
unquote()
Return values
array<string, string>

The parsed parameters.

On this page

Search results