我不確定strpos()
是否適用於此 任務。不確定strpos()是否正確使用
問題:
如果用戶輸入的仇恨或我的垃圾郵件可變 另一個字符串其返回的垃圾郵件過濾器的消息是正確的,但如果用戶 輸入垃圾郵件的變量,任何字符串不混各種它 傳遞進行處理。
我想要的輸入,從第一個字符串的最後一個字符串 檢查和t不與任何包含垃圾郵件變量字符串,然後 返回過程中,這裏是我的代碼
<?php
//messgae
error_reporting(E_ALL^E_NOTICE);
$msg = array();
$spam = "hate partisan party kill maim murder violence love sex fight beat assasinate thug steal sell bribe protest baricade bullets militia fear ";
$spam_array = explode(" ",$spam);
$check = strpos($spam, $_POST['message']);
if ($check == true) {
//do nothing
$msg['invalid'] = 'Spam filter test didnt allow your message';
} else {
$msg['valid'] = 'process';
}
if(isset($_POST['send'])){
$message= $_POST['message'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strpos</title>
</head>
<body>
<?php
if (isset($msg)) {
echo '<ul>';
foreach ($msg as $alert) {
echo "<li class='warning'>$alert</li>\n";
}
echo '</ul>';
}?>
<form action="" method="post">
<input name="message" type="text" />
<input name="send" type="submit" value="Submit" id="send" />
</form>
</body>
</html>
檢查''對== FALSE'代替 – Ghost
您使用strpos()不正確strpos'。它可以返回一個整數0,即'== false',但這只是表示它在'haystack'字符串的開始處找到了您的搜索字符串。此外,這種過濾器基本上是無用的:http://en.wikipedia.org/wiki/Scunthorpe_problem –
可能重複[檢查字符串是否包含幾個單詞之一](http://stackoverflow.com/questions/19178295/ check-if-string-contains-one-of-several-words) – rjdown