description
タグからデータを取得する際に助けが必要です。<a>
,<img>
などのテキストで構成されています。私が解析しようとしているXMLはthisxmlのタグ内でhtmlを解析する方法
というタグが記述テキストとともに得られたdescription
タグを除き、必要なすべてのデータを得ることができました。私が必要なのはimg
のsrcとdescriptionのテキストです。
マイコード:
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を解析するのはそれほど素晴らしいことではありません。