2016-07-27 52 views
0

我想在PHP中使用一種函數或方法來檢測隱藏文本中的粗言穢語。 的東西,將檢查字符串,如:在字符串中檢測混淆的粗俗名詞

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

,或者甚至

$string = "hey you sw3arw0rd!" 

的「臭罵」,如果它包含壞臭罵和虛假的,如果它不將返回true。 我不希望人們在我的網站上使用不好的字,請幫忙!

+1

這功能didnt存在,但你可以把它你自己,樂於助人的PHP函數'similar_text','soundex','levenshtein'你總是可以阻止一個有特殊字符的單詞,看'strpos',但是孔題目很多工作要做 – JustOnUnderMillions

+0

我可以用例子函數驗證嗎? – youmound

+0

閱讀本文:http://stackoverflow.com/questions/273516/how-do-you-implement-a-good-profanity-filter –

回答

0

只是一個簡單的例子來說明方向:

$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/>"; 
}