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 "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 was expecting the scrript to echo "desc1desc2", however nothing is ever echo'd.
*UPDATE
Here is some full code (I am making an rss reader)
$xml = new SimpleXMLElement('http://www.skysports.com/rss/0,20514,11661,00.xml', LIBXML_NOCDATA, true);
/* For each <character> node, we echo a separate <name>. */
foreach ($xml->item as $item) {
echo (string)$item->description;
}
$xml = new SimpleXMLElement('http://anxmlfile.xml', LIBXML_NOCDATA, true);