Home > Backend Development > PHP Tutorial > Examples to explain the definition and usage of php parse_str() function

Examples to explain the definition and usage of php parse_str() function

怪我咯
Release: 2023-03-07 22:14:01
Original
1702 people have browsed it

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)
Copy after login

Parameter details:

Parameter Description
stringRequired. 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:

<?php
parse_str("name=Bill&age=60");
echo $name."<br>";
echo $age;
?>
Copy after login

Code running results:

Examples to explain the definition and usage of php parse_str() function

Example 2

Storing variables in the array:

<?php
parse_str("name=Bill&age=60",$myArray);
print_r($myArray);
?>
Copy after login

Code running results:

Examples to explain the definition and usage of php parse_str() function

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template