Php Rss feed use img in CDATA -> content:encoded
Asked Answered
A

0

1

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.

Auria answered 2/8, 2015 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.