PHP 匹配单词代码在 php 5.1.6 上不起作用
我有一段代码在本地测试服务器上运行良好,但由于某种原因在实时服务器上运行不佳。 实时服务器上的 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;
}
}
i have piece of code that works fine on my local test server but on live server for some reason it does not.
Php version on live server is 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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先使用一些基本的调试来发现每个系统上发生的情况
First employ some basic debugging to discover what's happening on each system
您可以尝试将 preg_split 替换为
虽然如果您正在使用多字节字符串,则可能还需要 str_word_count 的附加第三个参数
You might try replacing your preg_split with
Though you may also need the additional 3rd parameter for str_word_count if you're working with multibyte strings