note 20034 deleted from function.serialize by aharvey

From: Date: Tue, 06 Nov 2012 02:02:01 +0000
Subject: note 20034 deleted from function.serialize by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191735@lists.php.net to get a copy of this message
Note Submitter: kjh90 at orgio dot net ---- 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. <?php 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); ... ?>

« previous php.notes (#191735) next »