从rss feed读取cdata

编程入门 行业动态 更新时间:2024-10-26 08:21:02
本文介绍了从rss feed读取cdata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用简单的代码阅读rss feed:

I'm reading a rss feed using simple code:

<?php $homepage = file_get_contents('www.forbes/news/index.xml'); $movies = new SimpleXMLElement($homepage); echo '<pre>'; print_r($movies); ?>

和类似这样的输出: SimpleXMLElement对象 ( [@attributes] =>数组 ( [版本] => 2.0 )

and the output like this: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 )

[channel] => SimpleXMLElement Object ( [title] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( ) [description] => SimpleXMLElement Object ( ) [language] => en-us [copyright] => Copyright 2009 Forbes LLC [item] => Array ( [0] => SimpleXMLElement Object ( [title] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( ) [author] => SimpleXMLElement Object ( ) [pubDate] => Sat, 05 Nov 2011 07:17:21 GMT [description] => SimpleXMLElement Object ( ) )

更多... 但是当我查看此页面的源代码时,我会得到如下信息:

and more.... but when I View source of this page I have Info like this:

<rss version="2.0"><channel><title><![CDATA[Forbes: News]]></title><link><! [CDATA[www.forbes]]></link><description><![CDATA[News and reports from Forbes]]></description><language>en-us</language><copyright>Copyright 2009 Forbes LLC</copyright><item><title><![CDATA[Benicio Del Toro Offered Villain Role In "Star Trek" Sequel - Is It Khan?]]></title><link><![CDATA[www.forbes/sites/markhughes/2011/11/05/benicio-del-toro-offered-villain-role-in-star-trek-sequel-is-it-khan/?feed=rss_home]]></link><author><![CDATA[Mark Hughes]]></author><pubDate>Sat, 05 Nov 2011 07:17:21 GMT</pubDate><description><![CDATA[Variety reports that actor Benicio del Toro is being offered the role of villain in the upcoming sequel to director J.J. Abram?s 2009 blockbuster franchise-reboot movie Star Trek. So far, Abrams and crew have kept a tight lid on details about the new Paramount film, and the identity of the main villain is a closely ...]]></description>

如何读取CDATA值并将其存储在mydatabase中.

how can I read and store CDATA value in mydatabase .

推荐答案

告诉SimpleXML将CDATA转换为普通文本:

Tell SimpleXML to convert CDATA into normal texts:

$homepage = 'www.forbes/news/index.xml'; $movies = simplexml_load_file($homepage, "SimpleXMLElement", LIBXML_NOCDATA);

应该使用 simplexml_load_file 代替file_get_contents.

相关答案:在simplehtmldom中删除cdata .

更多推荐

从rss feed读取cdata

本文发布于:2023-11-11 08:03:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:rss   feed   cdata

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!