爲什麼此代碼在我的託管中結果爲空,但在本地運行良好?空的RSS結果
$raw = file_get_contents($rssURL);
$xml = new SimpleXmlElement($raw);
echo "<b>RSS Items:</b><br /><br />";
foreach($xml->channel->item as $item) {
echo $item->title."</br >";
}
libxml
version:2.6.32; libxml2
版本:2.6.32
我也試過這個代碼:
# INSTANTIATE CURL.
$curl = curl_init();
# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL, $rssURL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
# GRAB THE XML FILE.
$xml = curl_exec($curl);
curl_close($curl);
# SET UP XML OBJECT.
$xmlObj = simplexml_load_string($xml);
echo "<b>RSS Items:</b><br /><br />";
foreach($xmlObj->channel->item as $item) {
echo $item->title."</br >";
}
echo "<br /><b>var_dump:</b><br><br>";
var_dump(libxml_get_errors())
的結果array(0) { }
有編碼這個片段用於Windows和Linux之間的任何差別(我不這麼認爲)?
任何想法的?
而不是var_dump($ xmlObj),var_dump(libxml_get_errors()) – Scott 2010-11-04 07:21:13
已更新,爲空的錯誤數組。 – 2010-11-04 07:44:08
是否curl_exec()拋出一個錯誤?另外,$ xml的值是多少? – Scott 2010-11-04 07:58:06