Home  >  Article  >  Backend Development  >  How to use php parse_str function?

How to use php parse_str function?

藏色散人
藏色散人Original
2019-05-23 10:48:142451browse

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);
?>

Output:

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

php parse_str() function example 2

<?php
parse_str(&#39;id=1&name="独孤求败"&#39;,$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!

Statement:
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