好的,所以我正在创建一个简单的回调函数来检查用户是否插入了禁用词。这是我到目前为止所拥有的:(这是使用 codeigniter 和 tankauth)
$this->form_validation->set_rules('firstname', 'First Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');
is_banned_word() 函数:
//Check if first or last name is a banned word
function is_banned_word($input) {
$banned_words = array("word1","word2",...."wordn"); //This is a really long array
foreach($banned_words as $words) {
if (stripos($input,$words) !== false) {
$this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
return FALSE;
}
else {
return TRUE;
}
}
return TRUE;
}
有什么帮助吗?