在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'
]
唯一设置的是开始[:
,然后是结束]
关键字可以是带有空格等的整句。
如何做到这一点?
3条答案
按热度按时间6psbrbz91#
你需要使用
explode
来分割你的strig。像这样:7d7tgy0s2#
怎么样:
输出:
pu3pd22g3#
试试这个,使用explode