【发布时间】:2013-07-07 05:26:03
【问题描述】:
我正在尝试使用simplexml_load_string 创建自己的RSS 提要(学习目的),同时在PHP 中解析http://uk.news.yahoo.com/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 标记?
谢谢
【问题讨论】:
标签: php xml-parsing simplexml