PHP读取feed,用PHP自带的simplexml系列函数实现

1.只读取标题

<?php
$xml=simplexml_load_file('http://www.site.com/rss.xml');
foreach($xml->channel->item as $item){
    echo '<a href="'.$item->link.'">';
    echo $item->title;
    echo '</a>';
    echo '<br/>';
    echo '<br/>';
}
?>

2.读取标题和摘要

<?php
$xml=simplexml_load_file('http://www.site.com/rss.xml');
foreach($xml->channel->item as $item){
    echo '<a href="'.$item->link.'">';
    echo $item->title;
    echo '</a>';
    echo '<br/>';
    $des=str_replace(' ','',str_replace('    ','',strip_tags($item->description)));
    $des=str_replace("\n",'',$des);
    $des=str_replace("\r",'',$des);
    echo $des;
    echo '<br/>';
}
?>
文章目录