My ww wikipedia

You see Wiki Is All 注册 | 登陆
Contact me!

我,在某年某月来到这个世界。于某年某月创建了该BLOG,其间在BLOG的 10 个分类中发表的 516 篇文章被评论了 45 次。

易用的RSS,XMl解析类 RSS_PHP

RSS_PHP is a free RSS Parser and XML Parser for PHP 5+, utilising the DOM to parse any valid XML Document including RSS, with provisional support for ATOM feeds.

Unlike many RSS Parsers, RSS_PHP also gives you full access to every part of the original RSS feed; including RSS attributes, RSS extensions, XML namespaces, XML stylesheets and node values.

I've specifically kept this RSS Parser as simple as possible. Here's a working example which will parse a full RSS feed, it'll also automatically convert the XML Document to UTF-8 from any other encoding:

<?php

    $rss 
= new rss_php;

    $rss->load('http://rssphp.net/rss.xml');

    $items $rss->getItems(); #returns all rss items
        
?>

IMPORTANT: A major peice of relatively unknown functionality is that RSS_PHP returns the actual DOMElements from the raw DOMDocument (although they have been modified slightly) - meaning that from any returned element you can access the full DOMDocument and have access to all the normal PHP DOM properties and methods.

Full documentation and examples of RSS_PHP are available on the site, or you can download the latest version of RSS_PHP for all your RSS & XML Parsing needs for free.

RSS PHP Information

I've spent years using XML in all it's formats, within that time I've seen literally thousands of people ask how can I parse RSS with PHP?; and the majority of the time the answer has been quite simply: use REGEX.

Personally, I think REGEX is fine solution, I've even used it to built my own XML & Markup parsers and established PHP frameworks on them, however the aim should be to keep things Really Simple, seeing as RSS isn't exactly the most complicated XML document to date.

Thankfully PHP (5+) already gives us everything we need to get started parsing RSS and XML, indeed it negates the need for REGEX or third-party extensions such as expat in this context.

Parsing RSS and XML in PHP using DOM Functions

With PHP 5 came the intoduction of the DOM Extension; to quote directly from the source:

The DOM extension allows you to operate on XML documents through the DOM API with PHP 5.

Rather than using any third party modules, or custom XML parsers like many other RSS parsers; RSS_PHP makes good use of the aforementioned DOM Extension.

RSS PHP Dependencies

As RSS_PHP utilises the DOM to parse RSS, and the DOM Extension is installed as part of the PHP Core, RSS_PHP's only dependency is PHP 5.

RSS PHP Internationalization and Character Encoding Support

RSS_PHP now features automatic XML Encoding Detection and conversion to UTF-8

Supported Versions of RSS

RSS_PHP works with all versions of RSS, including related modules, attributes and extensions, currently tested and verified against:

Tags: rss, xml, rss_php, php

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5

Leave a Comment

评论内容 (必填):