簡體   English   中英

PHP file_get_contents返回404

[英]PHP file_get_contents returns 404

我有一個非常奇怪的問題。 我試圖從3個小時到$ ht的輸出。 當我回顯$ ht時,結果為http://www.google.com 沒有問題。 但是當我使用$ ht變量執行file_get_contents時,沒有輸出。 我已經嘗試過卷曲也沒有輸出-404 ....

foreach ($hashtweet[1] as $ht)
        {

$html = file_get_contents($ht); //NOT WORKING
$html = file_get_contents("http://www.google.com"); // WORKING
echo $html;

//echo $ht;  = CORRECT OUT OF $ht = http://www.google.com

        }       

您應該使用修剪功能:

$html = file_get_contents(trim($ht)); 

字符串的開頭或結尾處可能有一些空格或其他白色字符

編輯

在您的問題中,您告訴我們$hthttp://www.google.com但在評論中您告訴了它是google.com 如果要獲取http://google.com ,則需要添加http:// 否則,這意味着您需要在當前目錄文件中使用名稱google.com

EDIT2

因此,您應該比較這兩個字符串。 在循環中添加:

if (trim($ht) == 'http://www.google.com') {
  echo "same strings<br />";
}
else {
  echo "there is difference<br />";
}

確保這些字符串相同或不同。 您告訴您$ ht返回string(21) "http://www.gooogle.com"所以它不可能不起作用,因為字符串http://www.gooogle.com字符串正好是21個字符。 您是否在運行file_get_contents之前或之后在循環內更改$ht變量?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM