标签:common 序列化 mon 保存 反序 get where data post
把复杂的数据类型压缩到一个字符串中
$stooges = array(‘Moe‘,‘Larry‘,‘Curly‘);
$new = serialize($stooges);
print_r($new);echo "<br />";
print_r(unserialize($new));
$shopping = array(‘Poppy seed bagel‘ => 2,‘Plain Bagel‘ =>1,‘Lox‘ =>4);
echo ‘<a href="next.php?cart=‘.urlencode(serialize($shopping)).‘">next</a>‘;
$new_cart = unserialize(stripslashes($cart)); //如果magic_quotes_gpc开启
$new_cart = unserialize($cart);
$fp = fopen(‘/tmp/cart‘,‘w‘);
fputs($fp,addslashes(serialize($a)));
fclose($fp);
//如果magic_quotes_runtime开启
$new_cat = unserialize(stripslashes(file_get_contents(‘/tmp/cart‘)));
//如果magic_quotes_runtime关闭
$new_cat = unserialize(file_get_contents(‘/tmp/cart‘));
在启用了magic_quotes_runtime的情况下,从数据库中读取序列化的数据也必须经过stripslashes()的处理,保存到数据库中的序列化数据必须要经过addslashes()的处理,以便能够适当地存储。
mysql_query("insert into cart(id,data) values(1,‘".addslashes(serialize($cart))."‘)");
$rs = mysql_query(‘select data from cart where id=1‘);
$ob = mysql_fetch_object($rs);
//如果magic_quotes_runtime开启
$new_cart = unserialize(stripslashes($ob->data));
//如果magic_quotes_runtime关闭
$new_cart = unserialize($ob->data);
标签:common 序列化 mon 保存 反序 get where data post
原文地址:http://www.cnblogs.com/mo-yang/p/6390562.html