您的位置:首页 > 编程语言 > PHP开发

[PHP] RSS to Array function

2012-04-16 22:15 281 查看
<?php

$rss_tags = array(
'title',
'link',
'guid',
'comments',
'description',
'pubDate',
'category',
);
$rss_item_tag = 'item';
$rss_url = 'http://www.pixel2life.com/feeds/adobe_fireworks.xml';

$rssfeed = rss_to_array($rss_item_tag,$rss_tags,$rss_url);

echo '<pre>';
print_r($rssfeed);

function rss_to_array($tag, $array, $url) {
$doc = new DOMdocument();
$doc->load($url);
$rss_array = array();
$items = array();
foreach($doc->getElementsByTagName($tag) AS $node) {
foreach($array AS $key => $value) {
$items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;
}
array_push($rss_array, $items);
}
return $rss_array;
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: