我正在尝试使用PHP中的simplexml_load_string
函数来解析http://uk.news.yahoo.com/rss
,并创建自己的RSS源(仅用于学习)。但我遇到了无法读取<description>
标签内的HTML标签的问题。
目前我的代码如下:
$feed = file_get_contents('http://uk.news.yahoo.com/rss');
$rss = simplexml_load_string($feed);
//for each element in the feed
foreach ($rss->channel->item as $item) {
echo '<h3>'. $item->title . '</h3>';
foreach($item->description as $desc){
//how to read the href from the a tag???
//this does not work at all
$tags = $item->xpath('//a');
foreach ($tags as $tag) {
echo $tag['href'];
}
}
}
有什么方法可以提取每个HTML标签吗?
谢谢