转自:http://qing.weibo.com/tag/unserialize
把庞大的数据范例紧缩到1个字符串外
$stooges = array('Moe','Larry','Curly');
$new = serialize($stooges);
print_r($new);echo "<br />";
print_r(unserialize($new));
$shopping = array('Poppy seed bagel' => 二,'Plain Bagel' =>一,'Lox' =>四);
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(一,'".addslashes(serialize($cart))."')");
$rs = mysql_query('select data from cart where id=一');
$ob = mysql_fetch_object($rs);
//若是magic_quotes_runtime合封
$new_cart = unserialize(stripslashes($ob->data));
//若是magic_quotes_runtime闭关
$new_cart = unserialize($ob->data);
转自:https://www.cnblogs.com/A-Song/archive/2011/12/13/2285619.html
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv1832