あなたは単に配列に悪い単語のリストを作成し、*で、このような言葉を置き換えるために、次のコードを使用することができます。
$badWords = array("badWord1", "badWord2", "badWord3", "badWord4", "badWord1");
$cleanUp = str_replace($badWords, "****", $originalString);
あなたはその拡張機能(例えばING、編、S、LY、など)を含め、このような単語を特定し、あなたが次のことを行うことができます不適切であることを示すメッセージで応答します。そのような悪い言葉の完全なリストをどのように取得してそれを特定すべきか。
// Array of Bad words
$words = array('badWord1','badWord2','badWord3','badWord14');
// Array of extention to words
$exten = array('','ed','ing','s');
// Input string
$str = 'this is a dam sentence';
// Create an array from input
$string = explode(' ',strtolower($str));
// Create a new array for all combinations of swear words
$wordList = array();
// Add all combinations to the new array
foreach($words as $word){
foreach($exten as $ext){
$wordList[] = $word.$ext;
}
}
// Loop through each input word, and check if it is a bad word or not
// FALSE = Good Words
// TRUE = Bad Words
$badWord = FALSE;
foreach($string as $s){
if(in_array($s, $wordList)){
$badWord = TRUE;
}
}
// Do something if output is good or bad in this case display a message
if($badWord)
echo 'This input contains inappropriate content';
else
echo 'This is valid input!';
「不適切な」とはどういう意味ですか? http://stackoverflow.com/questions/1835605/natural-language-processing-find-obscenities-in-english/1835666#1835666 – gbn
スクリプトのユーザーは、アポストロフィを含むクエリを使用してデータベース上の任意のSQLを実行できます。これはSQLインジェクションと呼ばれます。 – Sjoerd