简体   繁体   中英

Check if word is already in DB (PHP)

I'm trying to create a function which checks if word in a string is in the DB.

So, for example, I have a list with basic words in my DB. I type a sentence and would like to get all the words from that sentence which are not yet in the DB.

Any tips on how to work this out?

First convert search string to an array using this function

$str = "Hello user how are you.";
$find_it = explode(" ",$str);

Now use mysql query to find if this exist in DB or NOT...

 $filterExisting = "'" . implode("', '", $find_it ) . "'";
   $sql = "SELECT * FROM table WHERE field NOT IN (". $filterExisting .")";
   $result = $db->query($sql);

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