这是什么样的弦?如何反序列化此字符串? [英] What kind of string is this? How do I unserialize this string?

查看:87
本文介绍了这是什么样的弦?如何反序列化此字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么样的字符串?我该如何反序列化并从中取出数组?

What kind of string is this? How can I unserialize it and get the array out of it?

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

推荐答案

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

This is a serialized string. You can unserialize it with this function: unserialize(), like this:

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

输出:

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

旁注:

手册中的引言:

警告: 如果发生错误和未序列化序列化的FALSE值,则返回FALSE. 可以通过将str与serialize(false)进行比较或捕获已发出的E_NOTICE来捕获这种特殊情况.

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.

警告: 不要将不受信任的用户输入传递给unserialize(). 反序列化可能会由于对象实例化和自动加载而导致代码被加载和执行,并且恶意用户可能会利用此代码.如果需要将序列化的数据传递给用户,请使用安全的标准数据交换格式,例如JSON(通过json_decode()和json_encode()).

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.

这篇关于这是什么样的弦?如何反序列化此字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆