7位用戶,發佈了528篇文章,產生了91條評論!歡迎新會員:woshiyipianyun

發佈信息

 
 

易用的RSS,XMl解析类 RSS_PHP

freetor

freetor發表於254天 1小時 5分鐘前
來源:www.freetor.com 標籤:rssxmlrss_phpphp

 

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:



關注用戶

    最近還沒有登錄用戶關注過這篇文章…
暫無評論
共有 0 位網友發表了評論

評論

可用表情
huh  ohmy  wink  tongue  biggrin  laugh 
cool  rolleyes  dry  smile  mad  sad 
unsure  blink  ph34r  wub  wacko  laugh