开发者

recognize detect RSS feed using PHP

what is the best way to detect whether a given url is actually an RS开发者_运维知识库S feed?


It's tough to do reliably if the URLs you need to check are arbitrary.

One thing would be the content-type it serves. That can change, though, because (IIRC) IE needs text/xml to display an actual feed, and not to offer to download it. For more on the issue see here.

The second (and more reliable) thing would be to analyze the file's structure. Some ideas are here: How to detect if a page is an RSS or ATOM feed

The simplest way could be, as Pascal Martin recommends in that question, opening an URL with the Zend RSS reader. If that works out, it's a valid RSS resource, otherwise, it's not.


If you are a python developer this is quite easy. I faced the same situation a while ago. First install the libray "feedparser" on your system as a python library

For example your feed link is = "www.example.org/feed" chk the following

    import feedparser
    f=feedparser.parse("www.example.org/feed")
    if len(f.version)>0:
        print "It is a feed with version",str(f.version)   #Since the parsing is done and versions are allocated only to actual valid feeds otherwise an empty string is there 
    else:
        print "Not a Valid Feed Url"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜