Home >Backend Development >PHP Tutorial >这个怎么取到值

这个怎么取到值

WBOY
WBOYOriginal
2016-06-23 13:49:251048browse

string 'think:["aaa","bbb"]'
我要取到里面的aaa和bbb怎么做?


回复讨论(解决方案)

substr() 函数  自己百度

时常关注博客:http://www.phpthinking.com/ 

substr() 函数  自己百度

时常关注博客: http://www.phpthinking.com/

aaa与bbb的长度是固定的吗。 楼上的 substr()就可以。

substr

$s='think:["aaa","bbb"]';preg_match_all('/"(.+?)"/',$s,$m);print_r($m[1]);

我觉得还是用substr比较靠谱

其实可以先整理为json可以解释的格式,再json_decode得到数组。

$str = 'think:["aaa","bbb"]';$str = '{'.$str.'}';$str = preg_replace('/(\w+):/is', '"$1":', $str);$result = json_decode($str,true);print_r($result['think']);


Array
(
    [0] => aaa
    [1] => bbb
)

Statement:
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