2016-07-27 6 views
0

私は、隠されたテキストの誓いを検出するPHPの関数またはメソッドが必要です。以下のような文字列をチェックします 何か:文字列内の曖昧な誓語の検出

$string = "hey you swearword!" or 
$string = "hey you swear#word!" 

または多分

$string = "hey you sw3arw0rd!" 

「swearword」のため、それがない場合、それはその悪いswearwordとfalseが含まれている場合はtrueを返します。 私は人々が私のサイトに悪い言葉を使いたくない、助けてください!

方向を表示するだけの簡単な例
+1

が、あなたが自分でそれを作ることができ、参考になっPHP関数は 'similar_text'、' soundex'、 'levenshtein'しています'strpos'を参照して特別な文字を含む単語を常にブロックすることができますが、穴のトピックは多くの作業が必要です – JustOnUnderMillions

+0

例の関数の検証を行うことはできますか? – youmound

+0

これを読んでください:http://stackoverflow.com/questions/273516/how-do-you-implement-a-good-profanity-filter –

答えて

0

:didntのが存在する機能

$stopwords = ['swearword']; 

$test = ['swear#word','sw3arw0rd','goodword','swearw*rd','swe*rw*rd','swe*!**rd']; 

foreach($test as $word){ 
    foreach($stopwords as $stopword){ 
     if(levenshtein($stopword,$word)<=2){ 
      print "levenshtein: '$word' seems to mean $stopword<br/>"; 
      continue 2; 
     } 
    } 
    if(strlen(preg_replace('#[a-zA-Z]+#','',$word))!==0){#special char found 
     print "preg_replace: '$word' seems to have illegal chars<br/>"; 
     continue; 
    } 
    print "'$word' seems be NO stopword<br/>"; 
}