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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用