EchoFool Posted October 15, 2010 Share Posted October 15, 2010 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 More sharing options...
.josh Posted October 15, 2010 Share Posted October 15, 2010 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. Link to comment https://forums.phpfreaks.com/topic/215980-help-with-word-filter/#findComment-1122622 Share on other sites More sharing options...
phpfreak Posted October 15, 2010 Share Posted October 15, 2010 Nice function Crayon Violent... I'll snag that for something I'm working on now! Link to comment https://forums.phpfreaks.com/topic/215980-help-with-word-filter/#findComment-1122627 Share on other sites More sharing options...
EchoFool Posted October 16, 2010 Author Share Posted October 16, 2010 Thanks CV i will use your function! Great stuff! Link to comment https://forums.phpfreaks.com/topic/215980-help-with-word-filter/#findComment-1122647 Share on other sites More sharing options...
Philip Posted October 17, 2010 Share Posted October 17, 2010 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! Link to comment https://forums.phpfreaks.com/topic/215980-help-with-word-filter/#findComment-1122883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.