parse_strDescriptionparse_str() parses a query string (such as ?id=10&name=Ziggy%20Stardust") into variables that are then set in the local scope. If the optional $array argument is set, the variables are stored in $array as an array instead of being set in the local scope.
NotePHP automatically handles GET and POST data. In most cases, there is no need to decode query strings with this function.
NoteIf the magic_quotes_gpc configuration directive is enabled, the variables are processed with addslashes() before they're set.
CautionIf $array is not set, variables parsed out of the query_string overwrite variables that already exist in the local scope. See also
ExampleExample 1211. Demonstrate how parse_str() overwrites variables <?php $query_string = "PHP_SELF=oops"; echo <<<_EOS_ Before parsing the variable out of '$query_string' with parse_str(), \$PHP_SELF contained '$PHP_SELF'\n\n _EOS_; parse_str($query_string); echo <<<_EOS_ After parsing the variable out of '$query_string' with parse_str(), \$PHP_SELF contains '$PHP_SELF' _EOS_; ?> Sample output: Before parsing the variable out of 'PHP_SELF=oops' with parse_str(), $PHP_SELF contained '/test/test.php' After parsing the variable out of 'PHP_SELF=oops' with parse_str(), $PHP_SELF contains 'oops' Example 1212. Extract the variables from a stored query string <?php $query_string = "?id=acbd18db4cc2f85cedef654fccc4a4d8&i=F4&s=3"; parse_str($query_string, $output); var_dump($output); ?> Output: array(3) { ["id"]=> string(32) "acbd18db4cc2f85cedef654fccc4a4d8" ["i"]=> string(2) "F4" ["s"]=> string(1) "3" }
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|