note 94506 added to function.serialize
| From: | lisir2pro at gmail dot com | Date: | Mon, 09 Nov 2009 17:42:19 +0000 |
| Subject: | note 94506 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162667@lists.php.net to get a copy of this message | ||
I finally find out the simple solution of serializing and unserializing array which containing
slashes and quotes.
<?php
//Serialization
$title=str_replace(array('&','"','\'','<','>',"\t",),
array('&','"',''','<','>',' '),
$_POST['title']);
//couver any dangerous characters to safe one except slashes at first.
$somedata['title']=$title;
//update ths value of the key from the array you want to serialize
$SerializeStr=str_replace('\\','\\\\',serialize($somedata));
//this is the key one,serialize the array and replace slashes to double-slashes in the string of
serialized array .
mysql_query("UPDATE table SET data='$SerializeStr' WHERE ID='xxx' ");
//you can store this string up into your database
//Unserialization
$sqldata=mysql_query("SELECT data FROM table WHERE ID='xxx' ");
while($row=mysql_fetch_row($sqldata))
{
$data=unserialize($row[0]);
//now you can just unserialize the data without any problem.
}
?>
Because of this way without any addslashes() and stripslashes() functions and without using foreach
to cover any values in array(just cover the string of serialized array),it is faster to process the
string in array that will serialize and unserialize.
----
Server IP: 60.191.132.122
Probable Submitter: 119.129.62.52
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- https://master.php.net/note/edit/94506
Del: integrated -- https://master.php.net/note/delete/94506/integrated
Del: useless -- https://master.php.net/note/delete/94506/useless
Del: bad code -- https://master.php.net/note/delete/94506/bad+code
Del: spam -- https://master.php.net/note/delete/94506/spam
Del: non-english -- https://master.php.net/note/delete/94506/non-english
Del: in docs -- https://master.php.net/note/delete/94506/in+docs
Del: other reasons-- https://master.php.net/note/delete/94506
Reject -- https://master.php.net/note/reject/94506
Search -- https://master.php.net/manage/user-notes.php