2015-09-20 20 views
1

我试图做一个“搜索更新页面”用PHP与此代码:错误。如果用file_get_contents()函数

<?php 
    $update = file_get_contents('https://raw.githubusercontent.com/esteves25566/gestordebiblioteca/master/updater'); 
    if ($update == "build001"){ 
    }else{ 
     echo "<p style= \"color:red\">Existe um novo update! A nova build é a $update</p>"; 
    } 
?> 

但当现场输出build001,进行if语句去阅读它作为假,印刷“Existe um novo update!新星建造ébuild001” 我已经试过每一个! 感谢您的帮助!

+0

您是否尝试使用var_dump($ update)来查看您必须匹配的内容? – wmk

回答

1

有一个不可打印的字符在build001结束,它通过它的外观换行符。

试试这个测试

<?php 
    $update = file_get_contents('https://raw.githubusercontent.com/esteves25566/gestordebiblioteca/master/updater'); 
    if ($update == "build001\n"){ 
     echo 'gotit'; 
    }else{ 
     echo "<p style= \"color:red\">Existe um novo update! A nova build é a $update</p>"; 

    } 
+0

非常感谢!有用!!! –

0

不知道如果我在这里认识你,但

$update = file_get_contents('https://raw.githubusercontent.com/esteves25566/gestordebiblioteca/master/updater'); 
if (trim($update) <> 'build001') { 
    echo '<p style="color:red">Existe um novo update! A nova build é a ' . $update . '</p>'; 
    exit(); 
} 
+0

你应该写下你所做的。 – chris85

0

感谢这两个问题!它已经解决。 这两个问题的工作,但我更喜欢这个,因为我觉得更容易!

<?php 
$update = file_get_contents('https://raw.githubusercontent.com/esteves25566/gestordebiblioteca/master/updater'); 
if ($update == "build001\n"){ 
    echo 'gotit'; 
}else{ 
    echo "<p style= \"color:red\">Existe um novo update! A nova build é a $update</p>"; 

} 
?> 

非常感谢!