Home > Backend Development > PHP Tutorial > How to use php parse_str function?

How to use php parse_str function?

藏色散人
Release: 2023-04-06 18:42:01
Original
2483 people have browsed it

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 php parse_str function?

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

Output:

Array ( [id] => 23 [name] => John Adams )
Copy after login

php parse_str() function example 2

<?php
parse_str(&#39;id=1&name="独孤求败"&#39;,$array);
print_r($array);
?>
Copy after login

Output:

Array ( [id] => 1 [name] => "独孤求败" )
Copy after login

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!

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