1

我有一段代码在我的本地测试服务器上运行良好,但在实时服务器上由于某种原因它不能。实时服务器上的 PHP 版本是 5.1.6。

$subject = 'random words to check';   
$terms = explode(' ', 'word1 word2 check');
$wordIndex = array_flip(preg_split('/\P{L}+/u', mb_strtolower($subject), -1, PREG_SPLIT_NO_EMPTY));
foreach ($terms as $term) {
    if (isset($wordIndex[$term])) {
        echo "match>".$term;
    }
}
4

2 回答 2

0

首先使用一些基本的调试来发现每个系统上发生了什么

  • 转储 mb_strtolower 的输出
  • 转储 preg_split 的输出
  • 转储 array_flip 的输出
于 2010-07-13T06:55:33.593 回答
0

您可以尝试将 preg_split 替换为

$wordIndex = array_flip(str_word_count(mb_strtolower($subject), 2));

虽然如果您使用多字节字符串,您可能还需要 str_word_count 的附加第三个参数

于 2010-07-13T08:06:11.490 回答