I have the following xml
<rss> <channel> <item><title><![CDATA[bla]]></title><description><![CDATA[desc1]]></description><link>blah</link></item> <item><title><![CDATA[bleh]]></title><description><![CDATA[desc2]]></description><link>blahhh</link></item> </rss> </channel>
I want to get all the text in the "description", however it is surrounded by CDATA. I thought the following would work
$xmlurl = file_get_contents('http://anxmlfile.xml'); $xml = simplexml_load_string($xmlurl, null, LIBXML_NOCDATA); foreach ($xml->item as $item) { echo $item->description->innertext; }
I expected the script to echo "desc1desc2", but nothing will happen again.
* UPDATE
Here is the full code (I am reading an rss reader)
$xml = new SimpleXMLElement('http://www.skysports.com/rss/0,20514,11661,00.xml', LIBXML_NOCDATA, true); foreach ($xml->item as $item) { echo (string)$item->description; }
source share