PHP从字符串中提取文本
我有以下字符串: a:2:{s:4:"user";b:1;s:6:"userid";s:2:"48";}
我需要做的是从中提取数字 48它,在这种情况下。该数字可以有任意位数。我该怎么做呢?
I have the following string: a:2:{s:4:"user";b:1;s:6:"userid";s:2:"48";}
What I need to do is extract number 48 from it, in this case. This number could have any number of digits. How would I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来您面对的是序列化的字符串。因此,不要尝试使用正则表达式或任何其他字符串操作方法来获取该数字,而是尝试以下操作:
在此处了解 PHP 序列化:
It looks like you are facing a serialized strings. So, instead of trying to get that number using regular expression or any other string manipulation methods, try this:
Learn about PHP serialization here:
您到底想要实现什么目标?该字符串看起来像一个
serialize()
d 字符串,因此最好的选择是unserialize()
它What exactly are you trying to achieve? That string looks like a
serialize()
d one, so your best bet would be tounserialize()
it它看起来像序列化的字符串。
It looks like serialized string.
看起来这是一个序列化的关联数组。您只需要使用 unserialize() 将其从字符串转回数组。
Looks like that's a serialized associative array. You just need to use unserialize() to turn it back from a string into an array.
我看到的字符串是 PHP 中的序列化数组
要反序列化数组,请执行此操作,
我有反序列化数组,然后按名称访问数组参数
The string I see is serialized array in PHP
To unserialize array do this
I have unserialized array then access array param by name