PHP.nl

parse_str

parse_str

Parse a string as a URL query string

void **parse_str** string $string array $result

Parses as if it were the query string passed via a URL and sets keys in the provided array. If no is passed, values are instead set as variables in the current scope. string``result``result

stringThe input string.

result A variable passed by reference, which will be set to an array containing the key-value pairs extracted from . If the parameter is not passed, a separate variable is set in the local scope for each key. string``result

Waarschuwing: > Using this function without the parameter is highly and as of PHP 7.2. As of PHP 8.0.0, the parameter is . resultDISCOURAGED**DEPRECATEDresultmandatory

return.void

**Voorbeeld: Using **

<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";

// Recommended
parse_str($str, $output);
echo $output['first'], PHP_EOL;  // value
echo $output['arr'][0], PHP_EOL; // foo bar
echo $output['arr'][1], PHP_EOL; // baz
?>

Any spaces and dots in parameter names are converted to underscores when creating array keys or local variables. This is because variable names in PHP are not allowed to contain spaces or dots, but applies even when using this function with the recommended parameter.

resultVoorbeeld: name mangling

<?php
parse_str("My Value=Something", $output);
echo $output['My_Value']; // Something
?>

Opmerking: > is affected by the directive. Exceeding this limit triggers an , and any variables beyond the limit are not added to the result array. The default is 1000; adjust as needed. parse_strmax_input_varsE_WARNINGmax_input_vars

Opmerking: > All values populated in the array (or variables created if second parameter is not set) are already URL-decoded using the same rules as . result``urldecode

Opmerking: > To get the query string of the current request, you may use the variable . Also, you may want to read the section on . $_SERVER['QUERY_STRING']variables from external sources

parse_url``pathinfo``http_build_query``urldecode