duanhemou9834 2012-01-09 22:05
浏览 64
已采纳

用php获取[cdata]内容

I am reading this tutorial on fetching RSS feeds using PHP Simple XML.
Reason I wanna do it myself instead of Wordpress plugin is because of lack of displaying images.
Using this tutorial I thought I was going to be able to go through nodes myself and display what I want but I am not even fetching data I need because it is enclosed within ![CDATA]:

 <description>
<![CDATA[
<img src="http://images.highspeedbackbone.net/SKUimages/small/m17-1023-main666-tmc.jpg"/><br/> The Microsoft Office Home and Business 2010 Product Key Card brings together the roles of managing a business, running a household and helping with ho
]]>
</description>

So I am after that img tag, but it's not there using this code from tutorial:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://rss.linksynergy.com/promo.rss?promoid=3076&token=8c86517642801a8d4e1132xxxxxxxxxxxxxxxx35e66a3');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

$xml = new SimpleXMLElement($data);

Any suggestions welcome.

Thanks!

  • 写回答

1条回答 默认 最新

  • dragon8899 2012-01-09 22:19
    关注

    Try this:

    $xml = new SimpleXMLElement($data, LIBXML_NOCDATA);
    

    This will parse CDATA-Elements into normal text nodes so you can access them like any other text with $xml['decription']

    See http://www.php.net/manual/en/simplexmlelement.construct.php for reference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址