Instance
Parse the query string into the variable:
<?phpparse_str ("name=peter&age=43"); Echo $name. " <br> "; Echo $age;? >
Definition and usage
The Parse_str () function parses the query string into a variable.
Note: If the array parameter is not set, the variable set by the function overrides the already existing variable with the same name.
Note: The MAGIC_QUOTES_GPC setting in the php.ini file affects the output of the function. If enabled, the variable is converted by addslashes () before Parse_str () is resolved.
Grammar
Parse_str (String,array)
Parameter description
string is required. Specifies the string to parse.
Array is optional. Specifies the array name for the stored variable. This parameter indicates that the variable is stored in the array.
Technical details
Return value: no return value.
PHP version: 4+
Update log: In PHP 4.0.3, the array parameter has been added.
More examples
Example 1
To store variables in an array:
<?phpparse_str ("name=peter&age=43", $myArray);p Rint_r ($myArray);? >
To convert a URL parameter string to an array
$str = ' a=1&b=2&c=3 ';p arse_str ($str, $arr); Var_dump ($arr);//Output
Array (size=3) ' A ' =>string ' 1 ' (length=1) ' B ' =>string ' 2 ' (length=1) ' C ' =>string ' 3 ' (length=1)