duanlei1957 2011-01-06 16:05
浏览 18
已采纳

PHP不在现场阅读RSS文件,但在本地时读取正常

My local server reads the RSS fine, but when I upload it I'm getting this error:

Warning: fopen(http://webservice.weatherzone.com.au/rss/wx.php?u=13145&lt=aploc&lc=6439&fc=1) [function.fopen]: failed to open stream: HTTP request failed! in /var/www/vhosts/---------------------- on line 105
Error reading RSS data.

I cannot post the URL to the site because I'm still working on it and its a security issue. And I'm not able to modify the php.ini file...

This is the code where it is called:

$xml_parser = xml_parser_create();    
$rss_parser = new RSSParser();    
xml_set_object($xml_parser,&$rss_parser);    
xml_set_element_handler($xml_parser, "startElement", "endElement");    
xml_set_character_data_handler($xml_parser, "characterData");    
**$fp = fopen("http://webservice.weatherzone.com.au/rss/wx.php?u=13145&lt=aploc&lc=6439&fc=1","r")    
   or die("Error reading RSS data.");**    
while ($data = fread($fp, 4096))    
   xml_parse($xml_parser, $data, feof($fp))    
       or die(sprintf("XML error: %s at line %d",    
           xml_error_string(xml_get_error_code($xml_parser)),    
           xml_get_current_line_number($xml_parser)));    
fclose($fp);    
xml_parser_free($xml_parser);
  • 写回答

3条回答 默认 最新

  • dqask02082 2011-01-06 16:12
    关注

    Do not use fopen() to read files from Web.

    Try cURL instead, if installed:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($ch); // xml-code in $content
    curl_close($ch);
    

    http://www.php.net/manual/en/book.curl.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路