RSS feeds in PHP

后端 未结 6 755
感动是毒
感动是毒 2021-01-03 02:46

Just wondering if someone could suggest a PHP library that would allow me to read the data of an RSS feed and write it to a MySQL database. Also, if possible, provide a link

相关标签:
6条回答
  • 2021-01-03 03:11

    Reading data that simple is something you could use simplexml for.

    http://www.ibm.com/developerworks/library/x-simplexml.html

    From there you can see how easy it is to grab the data, instead of displaying, you store in a database.

    Gotchas: badly formatted rss (see above tut) different flavours of rss (ditto) evil values in the rss - it's foreign data and should be handled with suspicion dependency on allow_url_fopen - maybe use cURL

    0 讨论(0)
  • 2021-01-03 03:21

    Simplepie is probably the most popular PHP RSS library.

    0 讨论(0)
  • 2021-01-03 03:22

    RSS is a pretty simple format - there is no great need to use a separate library.

    I'd just use simplexml, because I don't wanna spend the effort learning another library, and keeping up with its development.

    Here is a simple PHP script for showing the latest Stackoverflor posts with simplexml:

    <?php
    $rss = simplexml_load_file('http://stackoverflow.com/feeds');
    ?>
    <h1><?php echo $rss->title; ?></h1>
    <ul>
    <?php
    foreach($rss->entry as $e) {
        echo "<li><a href=\"".$e->link['href']."\">";
        echo $e->title; 
        echo "</a></li>\n";
    }    
    ?>
    </ul>
    
    0 讨论(0)
  • 2021-01-03 03:22

    SimplePie is definitely the way to go. You can download and parse an RSS feed in under 10 lines of code. There is a tutorial here that shows you how.

    0 讨论(0)
  • 2021-01-03 03:22

    Magpie is an excellent RSS library

    http://magpierss.sourceforge.net/

    There's an example of using it here: http://www.olate.co.uk/articles/view.php?id=214

    Once you've used Magpie to grab an RSS feed you can store it in a string a save to a DB as you would with any other string.

    0 讨论(0)
  • 2021-01-03 03:28

    You can also give XPath a try, pretty simple to use.

    0 讨论(0)
提交回复
热议问题