开发者

Get feed titles from any RSS feed with php

开发者 https://www.devze.com 2023-04-10 04:45 出处:网络
I\'m attempting to build an RSS reader at the moment I\'m using php\'s simplexml using For example $xml->item->title

I'm attempting to build an RSS reader at the moment I'm using php's simplexml using For example

$xml->item->title

But however this is dependent on the开发者_如何学JAVA structure of the rss feed itself if the structure is different it won't work so I was wondering if theres a more broader and less specific way to grab all the titles from a RSS feed.

Thanks a lot


There is a RSS Specification document out there. You can find it at http://cyber.law.harvard.edu/rss/rss.html

Therefore, a RSS file always looks the same, but be carefull. There is always something like Atom.

You could use xPATH for searching within the RSS: http://nl.php.net/manual/en/simplexmlelement.xpath.php


maybe it´s an option for you using a contribution like this instead of invent the wheel again: http://www.phpclasses.org/package/3724-PHP-Parse-and-display-items-of-an-RSS-feed.html


You can use some Regex to filter the RSS files and split them into titles, etc. Whatever you want. As you will define which tags to grab data from.

Using something like: $regex = '/<(w+)[^>]*>(.*?)</\1>/s'; preg_match_all($reg_exp, $text, $match);


There are lot of feed formats. Writing code to comply all, is a bit difficult task. so..

I recommend using simple pie. http://simplepie.org/ or you can use google feed api also. here is a example using simple pie. http://simplepie.org/wiki/setup/sample_page

0

精彩评论

暂无评论...
验证码 换一张
取 消