小编dew*_*wey的帖子

始终无效的用户名有/无坏词

我正在尝试编写代码,拒绝任何包含坏词的用户名.无论我做什么 - 我都会收到"用户名无效".

$f = @fopen("censor.txt", "r");

$bw = fread($f, filesize("censor.txt"));
$banned_words = explode("\n", $bw);

function teststringforbadwords($wantusername, $banned_words)
{
    foreach ($banned_words as $banned_word) {
        if (stristr($wantusername, $banned_word)) {
            return FALSE;
        }
    }
    return TRUE;
}

if (!teststringforbadwords($wantusername, $banned_words)) {
    echo 'string is clean';
} else {
    echo('string contains banned words');
    $message = "Invalid username.";
}

@fclose($f);
Run Code Online (Sandbox Code Playgroud)

我目前正在学习PHP,并尝试了一切我能想到的工作 - 帮助!

php passwords

4
推荐指数
1
解决办法
123
查看次数

标签 统计

passwords ×1

php ×1