PHP-具有字符串和内爆(file())的比较运算符


PHP - comparison operators with string and implode(file())

今天我遇到了php:的问题

                $first = sha1($_POST['first']);
                $second = sha1($_POST['second']);
                $third = $first.$second;
                $sol = implode(file('./third/solution.txt'));
                if($third == $sol){
                    echo "Correct";
                }else{
                    echo "Not Correct";
                }

我使用echo打印$third和$sol,我看到它有相同的值,但$third==$sol返回总是false。我查了一些"或",但没有那种想法。有人对此负责吗?感谢

您可能希望在if条件中使用===而不是===。查看此链接使用==与strcmp 进行字符串比较

在比较通过加密或解密处理的字符串时,需要使用二进制安全比较:

if(strcmp($third,$sol) == 0) {
//do stuff here
}

http://php.net/strcmp