This isn’t going to be as interesting as your dirty little mind thinks it will be.

There’s an error in the following code snippet that returns the message “Can’t open http://www.blah.com/blah.xml”. Can you work out why?


$xmlfeed = "http://www.blah.com/blah.xml";
$news=@fread(fopen($url,"r"),10000) or die("Can't open $xmlfeed!");
$news = @file_get_contents($xmlfeed);
$p = xml_parser_create();
xml_parse_into_struct($p, $news, $vals, $index);
xml_parser_free($p);

Got it? Simple eh. Took you, what, a second or two to spot that I was trying to fopen a variable that I hadn’t declared or populated. Doing this late at night (by late, I mean after about 9pm which is what construes late for me these days) after a couple of cans of Stella, it took me nearly an hour to spot this elementary mistake.

As it happens, the file I was trying to retrieve can’t be opened using fopen anyway so I’ve resorted to using another function instead: CURL*. My issue now is that the page always throughs up some Java/JSP generated session id or cookie which I’ve got to deal with. At least, I think that’s what’s causing the Null Exception Error I’m currently getting. I know it can be done because I’ve passed the URL (not, incidentally, www.blah.com) into a demo of “MagicParser” which reads the XML without a problem. But I ain’t going to pay for it!

Anyone have any handy tips on this sort of thing? Or even now of a freeware PHP XML parser library/function that I can crib?

(And yes, Endie, CTRL-C before pasting is always a good idea. I’m still suffering from the same befuddlement as above which made me not do it this one time! :D )

*See following post.