php The parse_str() function is used to parse a string into multiple variables. The syntax is "parse_str(string,array)". The parameter string is the string to be parsed, and the parameter array is the name of the array that stores the variables. ; If the array parameter is not set, the variables set by this function will overwrite the existing variables with the same name.
How to use the parse_str() function?
php parse_str function: parse the query string into variables.
Syntax: parse_str(string,array)
Parameters:
string, required, specifies the string to be parsed.
array, optional, specifies the name of the array to store the variable. This parameter indicates that the variable will be stored in the array.
Note: If the array parameter is not set, the variables set by this function will overwrite the existing variables with the same name. 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().
php parse_str() function example 1
<?php parse_str("id=23&name=John Adams",$myArray); print_r($myArray); ?>
Output:
Array ( [id] => 23 [name] => John Adams )
php parse_str() function example 2
<?php parse_str('id=1&name="独孤求败"',$array); print_r($array); ?>
Output:
Array ( [id] => 1 [name] => "独孤求败" )
The above is the detailed content of How to use php parse_str function?. For more information, please follow other related articles on the PHP Chinese website!