2013-11-25 79 views
0

我試圖得到一個XML文件與網址:

$request="http://www.example.com/server.php?q=showphonenumbers"; 
$response = file_get_contents($request); 

如果我嘗試另一個請求,它會顯示,但不知何故,這個返回false。

var_dump($response);顯示:字符串(8334)「假」

文件看起來是這樣的:

<?xml version="1.0"?> 
<!DOCTYPE CallOverview> 
<CallOverview> 
<Calls Count="46"> 
<Call CallType="GeoCall" Customer="this account" StartTime="2013-11-22 18:58:07 (UTC)" Destination="+1...." Duration="00:23:40"/> 
<Call CallType="PSTNOut" Customer="this account" StartTime="2013-11-15 16:48:52 (UTC)" Destination="+1...." Duration="00:00:04"/> 
. 
. 
. 
</Calls> 
<MoreData>False</MoreData> 
</CallOverview> 

莫非最後假的moredata的唯一件事是顯示或者是文件不可讀?

+3

它是XML,並且您的瀏覽器正在嘗試呈現它。在你的瀏覽器中做一個'view source'。在你的vardump中的'string(8334)'應該是一個線索,有「不僅僅是滿足眼睛」 –

回答

1

在瀏覽器上,因爲您沒有放echo '<pre>';,瀏覽器試圖將xml渲染爲html,因此只有<MoreData>False</MoreData>被視爲文本並顯示。

如果您查看源代碼或通過cli運行它,您會看到您的內容在那裏。您也可以使用header("Content-type: text/plain");

+0

你是對的!如果我點擊查看源,我會看到數據。 – Diego

0

也許這是因爲你沒有把http://之前www.

$request="www.example.com/server.php?q=showphonenumbers"; 
相關問題