函数返回布尔值仅返回false

时间:2014-06-14 16:22:55

标签: php function validation

我有一个简单的功能,显然给我带来了很多麻烦。功能是:

function valid_mail($email) {
    $atpointers = strstr($email, "@");
    $spacepointers = count(explode(" ", $email));
    $dotpointers = strstr($email, ".");
    $ltpointers = strstr($email, "<");
    $gtpointers = strstr($email, ">");
    $illegalpts = $ltpointers + $gtpointers;
    if($atpointers >= 2 || $dotpointers == 0 || strlen($email) <= 6 || $illegalpts >= 1) { return false; } else { return true; }
}

在上下文中调用它:

if(valid_mail($email) === false) { // Code } else { // Code }

问题显然只会返回false。为什么会发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:0)

strstr返回被检查字符串的substr,而不是长度。改为使用strpos。