2015-05-02 20:55
浏览 52

从stackoverflow.com解析rss时出错。 在PHP中使用SimpleXML

I was trying to parse the rss of the tag PHP, from http://stackoverflow.com and tried to use something other than DOM Model, So I looked into SimpleXML. THis is my code:

    $xml = file_get_contents('https://stackoverflow.com/feeds/tag/php');
    $loaded = simplexml_load_string($xml) or die("There is a problem");
    $str1 = $loaded["entry"]["entry"][0]->title;
    echo $str1;

But nothing is displayed on the screen, and also no error is displayed! The sample data from https://stackoverflow.com/feeds/tag/php can be found at http://gourabt2.cloudapp.net/sample-data/sample_data.xml

Any Help would be very much appreciated! Thanks! Cheers!

图片转代码服务由CSDN问答提供 功能建议

我试图从 http://stackoverflow.com 并试图使用除DOM模型以外的东西,所以我研究了SimpleXML。 这是我的代码:

 $ xml = file_get_contents('https://stackoverflow.com/feeds/tag  / php'); 
 $ loaded = simplexml_load_string($ xml)或die(“有问题”); 
 $ str1 = $ loaded [“entry”] [“entry”] [0]  - &gt; title  ; 
 echo $ str1; 

但屏幕上没有显示任何内容,也没有显示错误! 来自<的示例数据 可以在 https://stackoverflow.com/feeds/tag/php /gourabt2.cloudapp.net/sample-data/sample_data.xml"rel =“nofollow noreferrer”> http://gourabt2.cloudapp.net/sample-data/sample_data.xml \ n

非常感谢任何帮助! 谢谢! 干杯!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dpy33121 2015-05-02 21:07

    You use array-access in SimpleXML to access attributes so:


    returns the attribute named "entry" from the document element.

    use arrow-access to get the element named "entry" instead:


    this returns the element named "entry".

    Additionally take care with namespaces. Parsing a feed with SimpleXML has been outlined already in existing Q&A material, please relate to it.

    点赞 打赏 评论
  • doubingqi5829 2015-05-02 21:03

    Try this out.

        $xml = file_get_contents('http://stackoverflow.com/feeds/tag/php');
        $loaded = simplexml_load_string($xml) or die("There is a problem");
        foreach($loaded->entry as $post) {
           echo $post->title . "


    join 2 tables - group by id order by date price asc
    using php variable in an sql query
    Clear browser cache memory by php code
    There is a error in parsing the rss from stackoverflow.com. using SimpleXML in PHP
    Modify Laravel Validation message response
    chained dropdown from database
    Php database handling
    How to load model with Codeigniter Webservice - Nusoap Server?
    multiple report download php adwords api
    Unable to confirm Amazon SNS subscription for SES bounces
    Comparing if values exist in database
    Better way to CURL to WCF
    PHP SaaS Facebook app: Host Page Tab ID and User ID
    PHP and Mysql - running over PDOStatement
    How to change form textbox value in Zend form annotation?
    connect Android with PHP, MySQL , unfortunately app has stopped in android emulator
    Auto increment a SESSION key ID
    Call PHP function in a class from a HTML form
    PHP SQL Preventing Duplicate User names: Catching Exception vs Select Query
    I am only able to grab the first group of text in between the tr need helping fixing my code
    How to run an external program in php
    How to connect to php in android using an async task?
    PHP Return HTML (Laravel / Lumen Framework)
    prestashop smarty if statement
    Cakephp OR condition Implementation
    Progress bar HTML5/PHP
    preg_match file url from jwplayer
    Does Cloudflare Cache HTML5 Video Embedded on PHP Page?
    PHP web service returns "403 forbidden" error
    点赞 打赏 评论
  • dtwy2858 2015-05-02 21:06

    That's because you have the wrong path. Here is the correction.

    点赞 打赏 评论

相关推荐 更多相似问题