php对象序列化和cookie的问题,反序列化false
$searchKeywords = array("羊奶","肥皂");
$searchKeywords = serialize($searchKeywords);//序列化
echo $searchKeywords;
setcookie("searchKeywords",$searchKeywords, time()+3600*24);
var_dump($_COOKIE['searchKeywords']);//查看存入的值
var_dump(unserialize($_COOKIE['searchKeywords']));//反序列化
看结果:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsISPrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdsATOfd3bkFGazxCMx8VesATMfhHLlN3XnxCMwEzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5iM1ETN0ITNxgzMwU2MxcTZjNmY0EjZ5kzYlFTN0IGNy8CX2AzLchDMxIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjL4M3Lc9CX6MHc0RHaiojIsJye.png)
由图得知:
$KeywordsStr = $_COOKIE['searchKeywords'];
$KeywordsStr= str_replace('\"', '"', $KeywordsStr);