duanpo1821 2015-08-12 05:23
浏览 69

我尝试执行simplexml_load_file时出现XML错误

I am trying to turn a XML data from another website into arrays in my program. This is what I have written so far:

<?php
$rss = 'http://headlines.yahoo.co.jp/rss/asahik-dom.xml';
$xml = simplexml_load_file($rss);
var_dump($xml);
?>

However, when I try to load the php page, it comes up with this error:

Warning: simplexml_load_file(http://headlines.yahoo.co.jp/rss/asahik-dom.xml) [function.simplexml-load-file]: failed to open stream: HTTP request failed! in /home/www2/it32.lady2.itall.co.jp/www/yxml.php on line 11

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://headlines.yahoo.co.jp/rss/asahik-dom.xml" in /home/www2/it32.lady2.itall.co.jp/www/yxml.php on line 11 bool(false)

FYI the $xml = simplexml_load_file($rss); is line 11.

Which part of my code has gone wrong? Please help.

  • 写回答

1条回答 默认 最新

  • duannv2081 2015-08-12 05:25
    关注

    Please try file_get_contents() to load file and then use SimpleXMLElement to parse it.

    Try

    $rss = file_get_contents('http://headlines.yahoo.co.jp/rss/asahik-dom.xml');
    $xml = new SimpleXMLElement($rss);
    print_r($xml);
    

    NOTE allow_url_fopen must be enabled in php.ini

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况