【问题标题】:simplexml_load_file Document is emptysimplexml_load_file 文档为空
【发布时间】:2012-10-18 15:05:12
【问题描述】:

我从 RSS 提要中提取:

http://search.library.utoronto.ca/UTL/index?Ntt=starcraft&Ntk=Anywhere&Ntx=mode+matchallpartial&N=0&Nu=p_work_normalized&Np=1&rss=1

如果您使用浏览器导航到该页面,您会得到一个漂亮的 xml 页面。

但是,如果我这样做了

simplexml_load_file("the above url");

在 php 中,我得到了

1: parser error : Document is empty
1: parser error : Start tag expected, '<' not found in my_file

那么为什么浏览器能得到它而PHP却不能呢?

如果我执行file_get_contents("the above url"),函数将失败并返回 FALSE。

【问题讨论】:

    标签: php xml-parsing simplexml


    【解决方案1】:

    该站点正在阻止来自 PHP 的请求。

    第一次运行

    <?php
    ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0');
    

    (或其他一些有效的用户代理),它会工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2022-11-18
      • 1970-01-01
      • 2012-04-13
      相关资源
      最近更新 更多