在 Wordpress 中处理序列化数据 [英] Working with serialized data in Wordpress
本文介绍了在 Wordpress 中处理序列化数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Wordpress 自定义字段中有以下序列化数据字符串:
I have the following string of serialized data in a Wordpress custom field:
$first_string = 'a:9:{s:5:"email";s:13:"test@test.com";s:4:"name";s:15:"Werner
Etsebeth";s:8:"address1";s:17:"1 Giligans
Island";s:8:"address2";s:1:"5";s:4:"city";s:9:"Cape
Town";s:5:"state";s:2:"AL";s:3:"zip";s:4:"7460";s:7:"
country";s:2:"US";s:5:"phone";s:0:"";}
$second_string = 'a:1:{i:4;a:1:{i:0;a:6:
{s:3:"SKU";s:0:"";s:4:"name";s:12:"Hypnotherapy";s:3:"url";s:72:"http://localhost
/mindworksa.co.za/wordpress/store/products/hypnotherapy
/";s:5:"price";s:5:"50.00";s:8:"quantity";s:1:"1";s:8:"download";s:0:"";}}}'
如何将信息分配给变量以便我可以单独访问,例如 $SKU = ""、$name = 等
How do I assign the info to variables so I can access individually eg $SKU = "", $name = etc.
我以前从未处理过序列化数据,任何帮助将不胜感激.
I've never worked with serialized data before and any help would be greatly appreciated.
非常感谢
推荐答案
我无法反序列化您的示例(您是否正确粘贴了它?)但 Wordpress 使用 serialize()
序列化对象以将它们存储在数据库中.
I am unable to unserialize your example (did you paste it in correctly?) but Wordpress uses serialize()
to serialize objects to store them in the database.
您可以使用 unserialize()
.
You can unserialize them using unserialize()
.
一个简单的例子:
$serialized = 'a:3:{i:0;s:5:"apple";i:1;s:6:"banana";i:2;s:6:"orange";}';
var_dump(unserialize($serialized));
输出:
Array
(
[0] => apple
[1] => banana
[2] => orange
)
这篇关于在 Wordpress 中处理序列化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文