【发布时间】:2016-11-04 11:03:53
【问题描述】:
我在 PHP 中有一个字符串:
$haystack = "[:something 1]Here is something 1 content[:something 2]here is something else[:something completely different]Here is the completely different content"
而且它可以永远持续下去。
所以,我需要将它们拆分成一个关联数组:
$final_array = [
'something 1' => 'Here is something 1 content',
'something 2' => 'here is something else',
'something completely different' => 'Here is the completely different content'
]
唯一设置的是开头[:,然后是结尾] 关键字可以是带有空格等的整个句子。
如何做到这一点?
【问题讨论】:
-
显示你的代码,你尝试了什么..
-
使用正则表达式匹配:查看 PREG_MATCH_ALL()
-
你试过什么?请发布一些示例数据和代码,并告诉我们什么不适合您。另外,请查看此链接:stackoverflow.com/help/mcve。