简体   繁体   中英

Most efficient way to run a check against a large number of words

I'm running a education software application. In the reading text section, I want to identify words that are in a word-list, and output a popup hover for those words. The word-list has about 30,000 words in it. I can put it into a MySQL table ~~or.... is there any more efficient way?

Specifically with respect to efficient, I mean reducing my server load. If the reading text has 500 words, that's about 400 MySQL calls to check each word (after eliminating basic words using a smaller array.)

If you simple want to compare all words passed by the user, you can also put all your words in one variable (not in array! in one line text), and by using strpos you will find them. I think it will be very fast!

$mywords = "word1 word2 word3 word4 ....... word40000"; 
$userWords = array('word2','other'); 
foreach($userWords as $word) {
    if(strpos($mywords, $word)!==false)
    {
        // you found a word!
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM