2013-02-18 34 views
1

我試圖打開一個XML文件,但我得到這些錯誤:SimpleXML的加載文件:未能打開流:重定向達到上限

Warning: simplexml_load_file(http://www.bva.fr/fr/rss/sondages.xml) [function.simplexml-load-file]: failed to open stream: Redirection limit reached, aborting in /xxx/import.php on line 93 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.bva.fr/fr/rss/sondages.xml" in /xxx/import.php on line 93 

Notice: Trying to get property of non-object in /xxx/import.php on line 99 

Warning: Invalid argument supplied for foreach() in /xxx/import.php on line 99 

99號線:

foreach($xml->channel->item as $item) 

我嘗試:

$xml = simplexml_load_file($url); 

和:

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
$content = curl_exec($curl); 
curl_close($curl); 

$xml = simplexml_load_string($content); 

但它仍然無法正常工作......

下面是XML文件:http://www.bva.fr/fr/rss/sondages.xml

你能幫幫我嗎?

回答

1

你也許可以嘗試添加補充捲曲選項:這是完整的例子誰可以這個RSS網站。

$options = array(
    CURLOPT_RETURNTRANSFER => true,  // return web page 
    CURLOPT_HEADER   => false, // don't return headers 
    CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
    CURLOPT_ENCODING  => "",  // handle all encodings 
    CURLOPT_USERAGENT  => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0", // something like Firefox 
    CURLOPT_AUTOREFERER => true,  // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
    CURLOPT_TIMEOUT  => 120,  // timeout on response 
    CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
); 

curl_setopt_array($curl, $options);在你的榜樣更換curl_setopt($curl, CURLOPT_URL, $url);

+0

是的!非常感謝 !它像一個魅力。 :) – Guillaume 2013-02-18 19:32:05

相關問題