simplexml_load_file and rss problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newzdog
Forum Newbie
Posts: 2
Joined: Thu Oct 22, 2009 9:51 am

simplexml_load_file and rss problem

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: simplexml_load_file and rss problem

Post 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.
newzdog
Forum Newbie
Posts: 2
Joined: Thu Oct 22, 2009 9:51 am

Re: simplexml_load_file and rss problem

Post 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.
Post Reply