note 84645 added to function.parse-str
| From: | MarkShust at osu1 dot php dot net | Date: | Wed, 23 Jul 2008 13:40:13 +0000 |
| Subject: | note 84645 added to function.parse-str | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142609@lists.php.net to get a copy of this message | ||
In addition to Maikel's posting, the following will iterate through previous arrays and
automatically apply them to the current array.
The following code was implemented for YUI's Cookie/subCookie utility in which all form
elements were stored as subcookies. This parses cookies and stores all cookie params (minus the
parent value) into $_POST variables. if you would like to put elements into array's of the
parent, just use the commented out line instead of the if statement.
<?php
// thise parses cookies and stores all fields as variables
foreach ($_COOKIE as $key => $value) {
// parse_str overwrites previous array values so we must merge the previous ones with new array
if (isset($_POST)) {
$_POST_old = $_POST;
parse_str($value, $_POST);
$_POST = array_merge($_POST_old, $_POST);
}
// this puts all elements as children of parent array
// comment out above if statement to use this instead
//parse_str($key, $_POST[$value]);
}
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
----
Server IP: 209.41.74.194
Probable Submitter: 65.106.146.42
----
Manual Page -- http://www.php.net/manual/en/function.parse-str.php
Edit -- https://master.php.net/note/edit/84645
Del: integrated -- https://master.php.net/note/delete/84645/integrated
Del: useless -- https://master.php.net/note/delete/84645/useless
Del: bad code -- https://master.php.net/note/delete/84645/bad+code
Del: spam -- https://master.php.net/note/delete/84645/spam
Del: non-english -- https://master.php.net/note/delete/84645/non-english
Del: in docs -- https://master.php.net/note/delete/84645/in+docs
Del: other reasons-- https://master.php.net/note/delete/84645
Reject -- https://master.php.net/note/reject/84645
Search -- https://master.php.net/manage/user-notes.php