PHP - parse_str
Trieda
Metóda - parse_str
(PHP 4, PHP 5, PHP 7)
The parse_str() function extracts variables from a string if
variables are in the form of the QUERY string (how we usually get them
from the URL address).
If the array is not set, variables are extracted into the current scope as if we created them there. However, it can sometimes be dangerous when the user knows it (or he thinks so). It means he can submit such variables which can damage our application. This function assumes that the string is from the user (e.g. cookies are processed this way), we will always use the array.
Using this function without specifying the second parameter throws a notice E_DEPRECATED since PHP version 7.2.0.
Procedurálne
- function parse_str (string $encoded_string, array &$result) : void
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $encoded_string | string | The string with variables. | |
| &$result | array | The array with unpacked variables. |
Mávratovej hodnoty
Vracia: void
The function does not return any value.
Príklady
<?php
$s = 'a=1&b=ict&array=[]&array[]=item';
$array = [];
parse_str($s, $array);
print_r($array);
