<?php
/*
*@作者:旭日
*@Email:54ano@163.com
*/

/*
*@实例化一个DOM类
*@version:1.0
*encoding:gb2312
*/
$dom = new DomDocument(‘1.0’, ‘gb2312’);
/*
*@载个文件
*/
$dom->load(‘http://rss.cnfol.com/news.xml’);
/*
*@获取channel节点
*/
$items = $dom->getElementsByTagName(‘channel’);

/*=====如果是中文内容,必须经过iconv编码转换,否则显示为乱码=====*/

/*
*@采channel下的子节点descrīption等节点的内容
*/
foreach (Array(‘descrīption’, ‘title’, ‘link’, ‘language’, ‘lastBuildDate’, ‘generator’, ‘copyright’) AS $node) {
   $global[‘cont’][$node] = iconv(‘utf-8’, ‘gb2312’, $items->item(0)->getElementsByTagName($node)->item(0)->nodeValue);
}
/*
*@采channel下的子节点image节点的信息
*/
foreach (Array(‘url’, ‘link’, ‘title’, ‘descrīption’) AS $node) {
   $global[‘cont’][‘image’][$node] = iconv(‘utf-8’, ‘gb2312’, $items->item(0)->getElementsByTagName(‘image’)->item(0)->getElementsByTagName($node)->item(0)->nodeValue);
}
/*
*@采channel下的子节点item节点的信息
*/
foreach ($items->item(0)->getElementsByTagName(‘item’) AS $key => $item) {
   foreach (Array(‘title’, ‘descrīption’, ‘link’, ‘author’, ‘pubDate’) AS $node) {
       $global[‘cont’][‘items’][$key][$node] = iconv(‘utf-8’, ‘gb2312’, $item->getElementsByTagName($node)->item(0)->nodeValue);
   }
}
print_r($global);
?>