我正在使用MyBB,一个名为NewPoints Shop的mod。
这是序列化的字段:
$barnInfo['newpoints_items'] = "a:7:{i:0;s:1:"2";i:1;s:1:"2";i:2;s:1:"2";i:3;s:1:"2";i:4;s:1:"5";i:5;s:1:"7";i:6;s:1:"7";}"
// the deserialized field represents this data:
4 Lumber (Item ID 2)
1 Mushroom (Item ID 5)
2 Carrot (Item ID 7)
(And perhaps 0 of every other item - there are 9 items: Item ID 1, 2, 3, ...7, 8, 9)
在他们的代码中,他们调用
$items = unserialize($barnInfo['newpoints_items']);
我很难处理这些数据。我想如果我能把反序列化的数据打印到屏幕上,我就能弄清楚如何处理它。但我不知道怎么打印出有意义的东西。我试过print_r,但没有成功。
// displays '1' , quite unhelpful!
print_r(unserialize($barnInfo['newpoints_items'] ))
// I tried and got very confusing results that don't seem to correspond at all http://blog.tanist.co.uk/files/unserialize/index.php
问题:我如何将反序列化的数据打印到屏幕上,以便我可以弄清楚什么是什么?
*答案:* MyBB在将内容打印到屏幕上时有点棘手,但它可以工作:"<pre>" . htmlspecialchars(print_r($items, true)) . "</pre> ... "
假设$barnInfo['newpoint_items']
实际上包含序列化数据,那么将print_r
包装在pre
标记中将使其更具可读性。
echo '<pre>';
print_r(unserialize($barnInfo['newpoint_items']));
echo '</pre>';