2015-09-20 23 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>"; 

} 
?> 

非常感謝!