PHP之序列化与反序列化讲解
serialize() 把变量和它们的值编码成文本形式 unserialize() 恢复原先变量 eg: $stooges = array('Moe','Larry','Curly');$new = serialize($stooges);print_r($new);echo "<br />";print_r(unserialize($new)); 结果: a:3:{i:0;s:3:"Moe";i:1;s:5:"Larry";i:2;s:5:"Curly";} Array ( [0] => Moe [1] => Larry [2] => Curly ) 当把这些序列化的数据放在URL中在页面之间传递时,需要对这些数据调用urlencode(),以确保在其中的URL元字符进行处理: $shopping = array('Poppy seed bagel' => 2,'Plain Bagel' =>1,'Lox' =>4);echo '<a href="next.php?cart='.urlencode(serialize($shopping)).'">next</a>'; margic_quotes_gpc和magic_quotes_runtime配置项的设置会影响传递到unserialize()中的数据。 如果magic_quotes_gpc项是启用的,那么在URL