【发布时间】:2015-06-06 14:01:22
【问题描述】:
我想做的是将 PHP 字符串拆分为一组子字符串,这些子字符串根据开始这些子字符串的“分隔符”字符分组到数组中。字符*、^ 和% 保留为分隔符。所以如果我有字符串"*Here's some text^that is meant*to be separated^based on where%the divider characters^are",它应该被拆分并放置在这样的数组中:
array(2) {
[0] => "*Here's some text"
[1] => "*to be separated"
}
array(3) {
[0] => "^that is meant"
[1] => "^based on where"
[2] => "^are"
}
array(1) {
[0] => "%the divider characters"
}
我完全迷失了这个。有谁知道如何实现这个?
【问题讨论】:
-
你试过explode()函数了吗?
-
“分隔符”的编程术语是分隔符。
-
我写了一个自定义的 sting 标记器,因为我老了,工作很无聊。 gist.github.com/Sammitch/774677bb7e82e4c6e128
标签: php arrays regex string substring