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

旧时模样 提交于 2019-12-12 10:18:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!