This article mainly introduces the example of using the Parse_str function that can automatically split query characters in PHP. this is a function that has not been seen in the small Editor. it is convenient to split the query string in the URL, for more information, see
Directly run the code:
The code is as follows:
$ Str = "1 & errid = 1 & balance = 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 to a variable.
Syntax
Parse_str (string, array)
Parameter description
String is required. Specifies the string to be parsed.
Array is optional. Specifies the name of the array that stores the variable. This parameter indicates that the variable is stored in the array.
Tips and comments
Note: If the array parameter is not set, the variables set by this function will overwrite the variables with the same name.
Note: The magic_quotes_gpc setting in php. ini affects the output of this function. If enabled, the variable will be converted by addslashes () before parse_str () resolution.
Example
Example 1
The code is as follows:
<? Php
Parse_str ("id = 23 & name = John % 20 Adams ");
Echo $ id ."
";
Echo $ name;
?>
Output:
The code is as follows:
23
John Adams
Example 2
The code is as follows:
<? Php
Parse_str ("id = 23 & name = John % 20 Adams", $ myArray );
Print_r ($ myArray );
?>
Output:
The code is as follows:
Array
(
[Id] => 23
[Name] => John Adams
)