Home  >  Article  >  Backend Development  >  Example of using the Parse_str function in PHP that can automatically split query characters_PHP tutorial

Example of using the Parse_str function in PHP that can automatically split query characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:21:50766browse

Examples of using the Parse_str function in PHP that can automatically split query characters

This article mainly introduces examples of using the Parse_str function in PHP that can automatically split query characters. The editor has not I have seen a function, now it is convenient to split the query string in the URL. Friends who need it can refer to it

Directly enter the code:

The code is as follows:

 $str = "1&errid=1&fee=2&balance=2582&fails=&msgid=634541149212681528&msg=All sent successfully.";

parse_str($str, $output);

echo $output['msgid']; //Output 634541149212681528

Definition and usage

 The parse_str() function parses the query string into variables.

Grammar

parse_str(string,array)

 Parameter Description

 string required. Specifies the string to be parsed.

array optional. Specifies the name of the array to store the variable. This parameter instructs the variable to be stored in an array.

Tips and Notes

 Note: If the array parameter is not set, the variables set by this function will overwrite variables with the same name.

Note: The magic_quotes_gpc setting in php.ini affects the output of this function. If enabled, variables are converted by addslashes() before being parsed by parse_str() .

Example

Example 1

The code is as follows:

parse_str("id=23&name=John%20Adams");

echo $id."

 ";

echo $name;

 ?>

Output:

The code is as follows:

 23

John Adams

Example 2

The code is as follows:

parse_str("id=23&name=John%20Adams",$myArray);

print_r($myArray);

 ?>

Output:

Copy the code. The code is as follows:

Array

 (

 [id] => 23

 [name] => John Adams

 )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/852813.htmlTechArticleUsage examples of the Parse_str function in PHP that can automatically split query characters. This article mainly introduces the automatic splitting of queries in PHP. Example of using the Parse_str function of characters, which I have never seen before...
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