我是否滥用了 CakePHP 的 Text::tokenize 实用程序?

Am I misusing CakePHP's Text::tokenize utility?

我正在尝试标记搜索查询,我调用 Text::Tokenize 函数的方式与 example on Cake's website 非常相似,但我 运行每当我有一个 " 并在它前面紧接着一个 - 时就会出现问题。

$query = 'question "help needed" -"garbage" contents of query';
$tokens = Text::tokenize( $query, ' ', '"', '"');

foreach ( $tokens as $index => $token) {
    echo $token . "\n";
}

我得到以下输出。

question
"help needed"
-"garbage" contents of query

但是,我不应该得到以下信息吗?我错过了什么?

question
"help needed"
-"garbage"
contents
of
query

值得注意的是,查询'question -"garbage" contents of query'

不会出现这种情况

这与 - 字符没有任何关系,但与多个 left/right 边界的出现有关。从 API 的描述来看,不清楚该方法是否支持多边界,所以我会说它要么不支持,要么是一个错误。

快速浏览一下源代码,我倾向于说这是一个错误,似乎它可能缺少更改 open 标志 here (might not be the only problem though, or maybe not even part of the problem at all, I can't test it right now). In any case you may want to open an issue over at GitHub,要求增强,分别提交行为作为错误。