微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 这是什么字符串?如何反序列化此字符串?

参见英文答案 > What is the type this string? a:1:{s:2:“en”;}                                    3个
这是什么字符串?我如何反序列化并从中获取数组?

a:2:{i:0;s:7:"Abogado";i:1;s:7:"Notario";}

解决方法:

这是一个序列化的字符串.您可以使用此函数对其进行反序列化:unserialize(),如下所示:

$str = 'a:2:{i:0;s:7:"Abogado";i:1;s:7:"Notario";}';
print_r(unserialize($str));

输出

Array ( [0] => Abogado [1] => Notario )

边注:

手册中的引用:

Warning:
FALSE is returned both in the case of an error and if unserializing the serialized FALSE value. It is possible to catch this special case by comparing str with serialize(false) or by catching the issued E_NOTICE.

Warning:
Do not pass untrusted user input to unserialize(). Unserialization can result in code being loaded and executed due to object instantiation and autoloading, and a malicIoUs user may be able to exploit this. Use a safe, standard data interchange format such as JSON (via json_decode() and json_encode()) if you need to pass serialized data to the user.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐