I have string like this:
我有这样的字符串:
a:3:{i:0;s:12:"Text One";i:1;s:16:"Text Two";i:2;s:14:"Text Three";}
I want to extract all occurrences within quotes to array. For example the result i want from above string should be:
我想在引号内提取所有出现的数组。例如,我想从上面的字符串结果应该是:
array["text One", "Text Two", "Text Three"]
How can I achieve this with as little code as possible?
如何用尽可能少的代码实现这一目标?
1 个解决方案
#1
The right approach to your problem depends on your specific needs (see the comments).. but to just answer your question directly:
解决问题的正确方法取决于您的具体需求(请参阅评论)..但只是直接回答您的问题:
$str = 'a:3:{i:0;s:12:"Text One";i:1;s:16:"Text Two";i:2;s:14:"Text Three";}';
preg_match_all('/"(.*?)"/', $str, $matches);
var_dump($matches[1]);
#1
The right approach to your problem depends on your specific needs (see the comments).. but to just answer your question directly:
解决问题的正确方法取决于您的具体需求(请参阅评论)..但只是直接回答您的问题:
$str = 'a:3:{i:0;s:12:"Text One";i:1;s:16:"Text Two";i:2;s:14:"Text Three";}';
preg_match_all('/"(.*?)"/', $str, $matches);
var_dump($matches[1]);