note 82140 added to function.parse-str
| From: | Maikel at osu1 dot php dot net | Date: | Fri, 28 Mar 2008 16:44:47 +0000 |
| Subject: | note 82140 added to function.parse-str | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137680@lists.php.net to get a copy of this message | ||
Be careful when use the second parameter, this function cleans array var first. Look this:
<?php
$vars["foo"] = "foovalue";
$queryString = "bar=barvalue&stuff=stuffval";
parse_str($queryString, $vars);
echo "<pre>";
print_r($vars);
echo "</pre>";
?>
Result:
Array
(
[bar] => barvalue
[stuff] => stuffval
)
it is solved by:
<?php
$prevVars["foo"] = "foovalue";
$queryString = "bar=barvalue&stuff=stuffval";
$newVars = array();
parse_str($queryString, $newVars);
$vars = array_merge($prevVars, $newVars);
echo "<pre>";
print_r($vars);
echo "</pre>";
?>
Result:
Array
(
[foo] => foovalue
[bar] => barvalue
[stuff] => stuffval
)
----
Server IP: 216.92.131.65
Probable Submitter: 190.79.224.85
----
Manual Page -- http://www.php.net/manual/en/function.parse-str.php
Edit -- https://master.php.net/note/edit/82140
Del: integrated -- https://master.php.net/note/delete/82140/integrated
Del: useless -- https://master.php.net/note/delete/82140/useless
Del: bad code -- https://master.php.net/note/delete/82140/bad+code
Del: spam -- https://master.php.net/note/delete/82140/spam
Del: non-english -- https://master.php.net/note/delete/82140/non-english
Del: in docs -- https://master.php.net/note/delete/82140/in+docs
Del: other reasons-- https://master.php.net/note/delete/82140
Reject -- https://master.php.net/note/reject/82140
Search -- https://master.php.net/manage/user-notes.php