Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

parse_str

Description

The parse_str of String for PHP parses the string into variables.

Syntax

parse_str(
    string $string,
    array &$result
): void

Parameters

string

The input string.

result

Variables are stored as array elements.

Return

No value is returned.

Examples

1 · string result

<?

$string = "key=value";

parse_str($string, $result);

echo $result["key"];

?>
value

2 · space

<?

$string = "my key=value";

parse_str($string, $result);

echo $result["my_key"];

?>
value

3 · array

<?

$string = "key[]=value1&key[]=value2+value3+value4&key[]=value5";

parse_str($string, $result);

print_r($result["key"]);

echo $result["key"][0] . PHP_EOL;
echo $result["key"][1] . PHP_EOL;
echo $result["key"][2];

?>
Array
(
    [0] => value1
    [1] => value2 value3 value4
    [2] => value5
)
value1
value2 value3 value4
value5
HomeMenu