Blog : PHP parse_str() Function
PHP parse_str() Function
--------------------------------------------------------------------------------
Complete PHP String Reference
--------------------------------------------------------------------------------
Definition and Usage
The parse_str() function parses a query string into variables.
Syntax
parse_str(string,array)
Parameter Description
string Required. Specifies the string to parse
array Optional. Specifies the name of an array to store the variables. This parameter indicates that the variables will be stored in an array.
Note: This parameter was added in PHP 4.0.3
--------------------------------------------------------------------------------
Tips and Notes
Note: If the array parameter is not set, variables set by this function will overwrite existing variables of the same name.
Note: The magic_quotes_gpc setting in the php.ini file affects the output of this function. If enabled, the variables are converted by addslashes() before parsed by parse_str().
--------------------------------------------------------------------------------
Example 1
parse_str("id=23&name=Kai%20Jim");
echo $id."
";
echo $name;
?>
The output of the code above will be:
23
Kai Jim
--------------------------------------------------------------------------------
Example 2
parse_str("id=23&name=Kai%20Jim",$myArray);
print_r($myArray);
?>
The output of the code above will be:
Array
(
[id] => 23
[name] => Kai Jim
)