【发布时间】:2017-08-05 17:06:22
【问题描述】:
这是我的代码:
$str = "this is a test"
$arr = explode(' ', $str);
/* output:
array (
0 => "this",
1 => "is",
2 => a,
3 => test
)
我要做的就是将此条件添加到explode() 函数中:
如果
a的单词后面跟着test的单词,则认为它们是一个单词。
所以这是预期的输出:
/* expected output:
array (
0 => "this",
1 => "is",
2 => a test
)
换句话说,我想要这样的东西:/a[ ]+test|[^ ]+/。但我不能使用提到的模式作为explode() 函数的替代方案。因为在现实中,有很多我需要关心的二分词。我的意思是有一组单词我想被视为一个单词:
$one_words("a test", "take off", "go away", "depend on", ....);
有什么想法吗?
【问题讨论】:
-
你问题的最后一句话让我很困惑。听起来
preg_split是你在那之前想要的。 -
downvoter,请发表评论并解释我的问题有什么问题?
标签: php regex function conditional explode