php 数组和字符串的问题

WBOY
Release: 2016-06-06 20:24:02
Original
1302 people have browsed it

请教一个php数组和字符串的转换问题。我有如下一个字符串:

<code>["approval","bbcode","emoji","english","flags","likes","simplified-chinese"]</code>
Copy after login
Copy after login

除了使用explode函数分割处理外,有没有其他的快速将其转换为数组的方法。

回复内容:

请教一个php数组和字符串的转换问题。我有如下一个字符串:

<code>["approval","bbcode","emoji","english","flags","likes","simplified-chinese"]</code>
Copy after login
Copy after login

除了使用explode函数分割处理外,有没有其他的快速将其转换为数组的方法。

<code>$array = json_decode('["approval","bbcode","emoji","english","flags","likes","simplified-chinese"]', true);</code>
Copy after login

可以用正则,但效率应该低一些

<code>$str = '"approval","bbcode","emoji","english","flags","likes","simplified-chinese"';
preg_match_all('/\".[^,]*\"/',$str,$out);
print_r($out);
</code>
Copy after login

php 数组和字符串的问题

也可以自己写c扩展,效率应该和explode差不太多

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!