What is the function of php parse_str() function?
The parse_str() function in PHP parses the query string into variables. Its syntax is as follows:
Syntax
parse_str(string,array)
Parameter details:
Parameter | Description |
---|---|
string | Required. Specifies the string to be parsed. |
array | Optional. Specifies the name of the array in which the variable is stored. This parameter indicates that the variable will be stored in an array. If a second variable array is set, the variable will be stored in this array as an array element instead. |
PS:If the array parameter is not set, the variables set by this function will overwrite the existing variables with the same name.
PS: 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() .
If string is the query string passed in by the URL, it is parsed into a variable and set to the current scope.
To get the current QUERY_STRING, you can use the $_SERVER['QUERY_STRING'] variable.
Example 1
Parse the query string into variables:
"; echo $age; ?>
Code running results:
Example 2
Storing variables in the array:
Code running results:
[Recommended related articles]:
Detailed explanation of the definition and usage of php parse_url() function
The above is the detailed content of Examples to explain the definition and usage of php parse_str() function. For more information, please follow other related articles on the PHP Chinese website!