0
我需要帮助从description
标签获取数据,它由<a>
,<img>
和一些文本组成。我试图解析XML是this如何解析html内部的xml标签
我设法得到我需要的所有数据,除了description
标签在那里我得到<a>
标签与说明文字一起。我需要的是img
的src和描述文字。
我的代码:
foreach ($rss->getElementsByTagName('item') as $node) {
/*$test = $node->getElementsByTagName('description');
$test = $test->item(0)->textContent;*/
var_dump($test);
exit;
$nodes = $node->getElementsByTagName('content');
if(!is_object($nodes) || $nodes === null || $nodes->length==0){
$linkthumbNode = $node->getElementsByTagName('image');
if(isset($linkthumbNode) && $linkthumbNode->length >0){
$linkthumb=$linkthumbNode->item(0)->nodeValue;
if(empty($linkthumb)||$linkthumb == " "){
$linkthumb = $linkthumbNode->item(0)->getAttribute('src');
}
}else{
$linkthumb = "NO IMAGE";
}
}else{
$linkthumb = $nodes->item(0)->getAttribute('url');
}
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
$desc = $node->getElementsByTagName('description')->item(0)->textContent;
$link = $node->getElementsByTagName('link')->item(0)->nodeValue;
$img = $linkthumb;
$date = $node->getElementsByTagName('pubDate');
if(isset($date) && $date->length >0){
$date = $date->item(0)->nodeValue;
}else{
$date = "no date provided";
}
$item = array (
'title' => $title,
'desc' => $desc,
'link' => $link,
'img' => $img,
'date' => $date,
);
array_push($feed, $item);
}
XML描述标签是:
<description>
<a href="http://timesofindia.indiatimes.com/life-style/health-fitness/diet/9-food-combos-to-make-you-lean/articleshow/20984744.cms"><img border="0" hspace="10" align="left" style="margin-top:3px;margin-right:5px;" src="http://timesofindia.indiatimes.com/photo/20984744.cms" /></a>Nine food combinations that will make staying healthy and looking fit easier
</description>
我需要什么:http://timesofindia.indiatimes.com/photo/20984744.cms
图像和Nine food combinations that will make staying healthy and looking fit easier
作为我的描述。
有人可以帮助我吗?我并不擅长PHP和解析XML。