0

好的,所以我正在创建一个简单的回调函数来检查用户是否插入了禁用词。这是我到目前为止所拥有的:(这是使用 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;
}

有什么帮助吗?

4

1 回答 1

0

你的问题是什么?

function is_banned_word($input) {
    $banned_words = array("word1","word2",...."wordn"); //This is a really long array
        if (in_array( $input , $banned_words )) {
            $this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
            return FALSE;
        }
    return TRUE;
}
于 2012-09-15T02:47:49.317 回答