I'm currently working on an application that uses php's simplexml to interpret rss feeds from multiple sites. I've managed to get this to work with both Atom and RSS feeds, however one feed only works sometimes, which doesn't really make sense. The feed is located http://www.popsci.com/rss.xml. I'm wondering if the feed itself is malformed, or if there may be something that it is doing that is valid, but unusual. I've looked it up and down but can't find anything wrong. My code interprets many other feeds perfectly, so I'm wondering why this one gives it trouble. And only sometimes. What I mean by that, is that sometimes it will successfully interpret the feed, but other times, the call to simplexml_load_file()
fails and returns false.
I do have an error log and this is what has been reported (the same thing every time it fails):
[08-Nov-2010 03:30:17] PHP Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.popsci.com/rss.xml:1: parser error : Start tag expected, '<' not found in /Applications/MAMP/cmb/cron.php on line 15
[08-Nov-2010 03:30:17] PHP Warning: simplexml_load_file() [function.simplexml-load-file]: � in /Applications/MAMP/cmb/cron.php on line 15
[08-Nov-2010 03:30:17] PHP Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /Applications/MAMP/cmb/cron.php on line 15
But I'm not sure what to make of these errors, and I would appreciate it if someone could point me in the right direction. Thanks! (P.S. line 15 in cron.php is the call to simplexml_load_file()
)
php -r 'echo simplexml_load_file( "rss.xml" )->channel->title;'
it prints the title. If I use the URL, in double quote it gives your errors. With URL in single quotes, it works. I'm not a PHP expert: I don't know why this makes a difference. Maybe someone can explain. – Steven D. Majewski