I need to display only the image from the CDATA content.
<item>
<title>... </title>
<link>... </link>
<description>... </description>
<category>... </category>
<pubDate>... </pubDate>
<guid>... </guid>
<content:encoded><![CDATA[<a href="..."><img alt="" src="..."/></a>...]]></content:encoded>
<enclosure url="..." type="image/jpeg" length="171228"></enclosure>
</item>
my code i tried looks like this an works fine for the part
<?php
$html = "";
$url = "http://www....";
$xml = simplexml_load_file($url);
for($i = 0; $i < 1; $i++){
//works fine with <description> part
$description = $xml->channel->item[$i]->description;
preg_match("/<img[^>]+\>/i", $description, $matches);
if (isset($matches[0])) {
$html .= $matches[0];
//echo "<br/>show img<br/>";
} else {
$html .= $description;
echo "<br/>there is no img";
}
}
echo $html;
?>
now i need a method for the part and show the image separately. can someone help me fix this?
maybe it is possible to use the url in to display the image.
来源:https://stackoverflow.com/questions/31771729/php-rss-feed-use-img-in-cdata-contentencoded