我正在使用简单的代码阅读RSS订阅源:
<?php
$homepage = file_get_contents('http://www.forbes.com/news/index.xml');
$movies = new SimpleXMLElement($homepage);
echo '<pre>';
print_r($movies);
?>
Run Code Online (Sandbox Code Playgroud)
和输出如下: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.com 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
(
)
)
Run Code Online (Sandbox Code Playgroud)
还有更多....但是当我查看此页面的来源时,我有这样的信息:
<rss version="2.0"><channel><title><![CDATA[Forbes.com: News]]></title><link><! [CDATA[http://www.forbes.com]]></link><description><![CDATA[News and reports from Forbes.com]]></description><language>en-us</language><copyright>Copyright 2009 Forbes.com LLC</copyright><item><title><![CDATA[Benicio Del Toro Offered Villain Role In "Star Trek" Sequel - Is It Khan?]]></title><link><![CDATA[http://www.forbes.com/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>
Run Code Online (Sandbox Code Playgroud)
如何在mydatabase中读取和存储CDATA值.
hak*_*kre 10
告诉SimpleXML将CDATA转换为普通文本:
$homepage = 'http://www.forbes.com/news/index.xml';
$movies = simplexml_load_file($homepage, "SimpleXMLElement", LIBXML_NOCDATA);
Run Code Online (Sandbox Code Playgroud)
这应该为你做,simplexml_load_file而不是使用file_get_contents.
相关解答:在simplehtmldom中删除cdata.
| 归档时间: |
|
| 查看次数: |
4906 次 |
| 最近记录: |