Home >Backend Development >PHP Tutorial >PHP parses the query string into a variable using the function parse_str()
Example
Parse the query string into a variable:
<?php parse_str("name=Peter&age=43"); echo $name."<br>"; echo $age; ?>
Definition and usage
parse_str() function parses the query string into a variable.
Note: If the array parameter is not set, the variables set by this function will overwrite the existing variables with the same name.
Note: The magic_quotes_gpc setting in the php.ini file affects the output of this function. If enabled, variables are converted by addslashes() before being parsed by parse_str() .
Syntax
parse_str(string,array)
Parameter Description
string Required. Specifies the string to parse.
array Optional. Specifies the name of the array to store the variable. This parameter instructs the variable to be stored in an array.
Technical details
Return value: No return value.
PHP Version: 4+
##Change Log: In PHP 4.0.3 , added array parameter. More examplesExample 1Storage variables into an array:<?php parse_str("name=Peter&age=43",$myArray); print_r($myArray); ?>Convert the url parameter string into Array
$str = ‘a=1&b=2&c=3’; parse_str($str, $arr); var_dump($arr); //输出rrree
The above is the detailed content of PHP parses the query string into a variable using the function parse_str(). For more information, please follow other related articles on the PHP Chinese website!