Jump to content

Help with word filter


EchoFool

Recommended Posts

Hey,

 

I have a word filter which is dectecting strings that are only embedded in words. Which i don't want it to do.

 

For example:

 

If i want to filter "FR" and some one puts france - it flags it because france contains FR.

 

How do i make it only look for "FR" on its own seperated from a word instead of it flagging nearly all words with the two letters together?

 

Heres my filter:

 

 

$text = 'testing';  //this should not return 1
  // fill this array with the bad words you want to filter and their replacements
     $bads = array ("test");

                
foreach($bads as $key => $search_needle) {

   if(stristr($text, $search_needle) == TRUE) {
       return(1);
       break;
        }
    }

Link to comment
https://forums.phpfreaks.com/topic/215980-help-with-word-filter/
Share on other sites

if (preg_match('~\b'.$search_needle.'\b~i',$text)) {

 

on a sidenote, if you're looking for something somewhat more robust, check out this word filter function I created a while back.  Basically it lets you specify bad words and define masks for them.

if (preg_match('~\b'.$search_needle.'\b~i',$text)) {

 

on a sidenote, if you're looking for something somewhat more robust, check out this word filter function I created a while back.  Basically it lets you specify bad words and define masks for them.

That sure is handy!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.