2011-09-02 52 views
0

我正在嘗試檢索URL的狀態。我正在寫PHP代碼來檢索它,但我沒有得到輸出。沒有顯示任何內容。在PHP中獲取URL的HTTP響應 - XML

我正在讀取來自xml文件的url並將其存儲在變量中。我在做

file_get_contents($url); 

echo $http_respone_header[0]; 

$url包含我從xml文件讀取的url。

+1

你有'http_respone_header'一個錯字 - 也許這已經解決了這個問題? –

+0

這個ISNT複製 - 從代碼刪除.....錯字只在這裏,在問題中,代碼拼寫正確。 – Nibhrit

+0

什麼'print_r($ http_response_header);'show? –

回答

1

你正在做的事不是獲取URL狀態,而是獲取網站的內容。如果URL錯誤/無效file_get_contents()返回false,如文檔in here

返回false如果您試圖獲取狀態您可以簡單地使用此站點上其他主題中描述的解決方案。

<?php 

$url = 'http://www.wp.pl'; 
$handle = curl_init($url); 
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 

/* Get the HTML or whatever is linked in $url. */ 
$response = curl_exec($handle); 

/* Check for 404 (file not found). */ 
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 

echo $httpCode; 

curl_close($handle); 


?> 

鏈接所提到的話題:here