I have a problem trying to parse RSS feed in XML. The problem arises when the strings contain the ![CDATA[ parameter. I have looked for some solutions here already, but none of them seemed to work.
The code for reading the feed looks like this:
$xmlDoc = new DOMDocument();
$xmlDoc->load($url);
$x = $xmlDoc->getElementsByTagName('item');
$xLength = $xmlDoc->getElementsByTagName('item')->length;
for ($i=0; $i<$xLength; $i++) {
$itemTitle = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$itemLink = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$itemDesc = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
}
Now when I then echo the items, everything works fine, given the CDATA is not delimiting the string.
Once the description or any other part of the text is between the CDATA, it does not read it. I tried inserting the (string) in front of the $itemDesc, but that for some reason worked but only for the first item, the next items, if they containted CDATA in description, nothing appeared.