Php Match words code not working on php 5.1.6
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开发者_如何学JAVA_NO_EMPTY));
foreach ($terms as $term) {
if (isset($wordIndex[$term])) {
echo "match>".$term;
}
}
First employ some basic debugging to discover what's happening on each system
- dump the output of mb_strtolower
- dump the output of preg_split
- dump the output of array_flip
You might try replacing your preg_split with
$wordIndex = array_flip(str_word_count(mb_strtolower($subject), 2));
Though you may also need the additional 3rd parameter for str_word_count if you're working with multibyte strings
精彩评论