Page 1 of 1

simplexml_load_file and rss problem

Posted: Thu Oct 22, 2009 9:53 am
by newzdog
Hi,

I have a problem parsing an rss feed using simplexml_load_file - this is strange as i have used the same code to parse literally 1000s of different feeds in the past, and even stranger in that if i put the feed source on our server as a .xml file then my code parses it successfully.

The relevant code snippet:
$xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2", ... XMLElement', LIBXML_NOCDATA);

The errors i get are:
Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:1: parser error : Start tag expected, '<' not found in [my php script]
Warning: simplexml_load_file() [function.simplexml-load-file]: 2977 in [my php script]
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in [my php script]


Any ideas or suggestions will be much appreciated thanks.
d.

Re: simplexml_load_file and rss problem

Posted: Thu Oct 22, 2009 1:24 pm
by requinix
The site is sending the RSS in a chunked encoding. All you need to know is that screws up the XML.

Use something like cURL to download the feed, then run SimpleXML off the local copy.

Re: simplexml_load_file and rss problem

Posted: Fri Oct 23, 2009 5:26 am
by newzdog
Thanks. I guess the chunked encoding explains the extra characters i can see when i use file_get_contents to copy the feed locally - i'll try curl.