SimpleXML真是个好东西

这两天写一个页面需要访问一个RSS并且读取rss内的的文章标题和文章的链接,就尝试了一下PHP5的新特性也就是这个SimpleXML,直接支持xpath获取,确实很方便啊 :

$file = file_get_contents("__YOUR__RSS__URL__HERE__");
 
$xml = new SimpleXMLElement($file);
 
$titles = $xml -> xpath("/rss/channel/item/title");
$links = $xml -> xpath("/rss/channel/item/link");

然后就对$titles和$links这两个数组进行操作即可。

No Responses

Leave a Comment

(Necessary)

(Necessary, will not be published)

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.