note 20034 added to function.serialize
| From: | kjh90 at orgio dot net | Date: | Wed, 20 Mar 2002 05:43:37 +0000 |
| Subject: | note 20034 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27978@lists.php.net to get a copy of this message | ||
If you want to put serialized data into DB, you have to add slashes.
At this point, there's a problem. If you got data via HTTP POST method, the data has slashes
already. I tried to work with "array_walk" or "array_map", but it doesn't
work when the data has array.
So make extended stripslashes function.
function my_stripslashes($vals) {
if (is_array($vals)) {
foreach ($vals as $key=>$val) {
$vals[$key]=my_stripslashes($val);
}
} else {
$vals = stripslashes($vals);
}
return $vals;
}
$data = addslashes(serialize($_POST));
...
$SQL="insert into DB() values($data)";
...
$SQL="select data from DB";
...
$data = my_stripslashes($data);
...
--
http://www.php.net/manual/en/function.serialize.php
http://master.php.net/manage/user-notes.php?action=edit+20034
http://master.php.net/manage/user-notes.php?action=delete+20034
http://master.php.net/manage/user-notes.php?action=reject+20034