PHP将数据反序列化为空,为什么会这样?

时间:2011-09-08 12:35:50

标签: php

我的序列化数据看起来像这样

a:6:{i:0;s:12:"Early humans";i:1;s:32:"Apes And Hominids   Dart's Find";i:2;s:36:"The hunter gatherers of South Africa";i:3;s:25:"Early Humans The Eve Gene";i:4;s:50:"Australopithecines, Homo ergaster and Homo sapiens";i:5;s:21:"Landscapes of history";}

当我尝试反序列化时,结果是空的。

我的代码:

$urlnames = unserialize($row['url_name']);

foreach($urlnames as $names){

  echo $name;
}

我做错了什么?

由于

3 个答案:

答案 0 :(得分:4)

序列化字符串错误。 “Dart的查找”字符串中应该还有一个字符 - 我不知道为什么缺少一个字符,但添加一个字符会使其正常工作。

<强> See for yourself

答案 1 :(得分:1)

在索引1上,您只有31个字符,这就是它无法正常工作的原因。

答案 2 :(得分:1)

您是否从db获得序列化字符串?

如果你从那里得到它,那么你的反斜杠就会丢失。那是你的第32个角色。

关于反斜杠和数据库的更多信息请查看google / yahoo / bing ...