我有一个很小的PHP代码,它读出一个包含y或n或b的文件。 我已经回显了文件输出,它显示完美y。现在,如果我将变量与y进行比较,它就不接受它并继续使用else。
$result = mysqli_query($db, "SELECT ID FROM review WHERE reviewer_ID='$reviewer_ID' AND products_ID='$products_ID'");
if ($result->num_rows > 0){
// this person has already reviewed it
echo "you have already reviewed it<br />";
echo "<p><a href=\"../page.php?productid=". $F_products_ID ."\">Zurück</a></p>";
}else{
// $out= y if its valid and $out= n if its a invalid review
$out = shell_exec ("/home/script.sh $reviewlink");
// time for the script to run. needs aprx. 1-2 seconds.
sleep(2);
// variables for PHP
$valid = file_get_contents('/home/script/valid');
$digits = file_get_contents('/home/script/digits');
// PHP sends it to the DB if true
if ($out == 'b' or $valid == 'b'){
echo "<p>We have an issue right now!</a></p>";
header('location:issue.php?productid=$F_products_ID');
} else {
echo "Review Status from file: $valid <br>";
echo "Review Status from script: $out <br>";
echo "Digits in Review: $digits <br><br>";
if (($out == 'y' or $valid == 'y') and $digits >= $mindigits){
//do stuff
所以回声和有效显示y和数字正确,但将它们与y(或与心灵)进行比较似乎不起作用。 PHP认为y = / y而我得不到它......
答案 0 :(得分:0)
尝试将[0]
添加到变量中:
if ($out[0] == 'y' or $valid[0] == 'y'){ ... }
因此,只有第一个字符用于比较过程。