1

I'm attempting to parse a wordpress RSS feed from PHP. The following works fine on my local server, but not with the host my site is actually on.


$url = "../blog/feed/"; $rss = simplexml_load_file($url);

foreach ($rss->channel->item as $item) { //Do stuff
}

However, on the server my site is hosted, I get the error "I/O warning : failed to load external entity"

Interestingly enough, though, whenever I manually save the RSS file as an xml file and point to that file, everything works fine. So while I could manually save and upload the xml file after every post I do, I'd rather automate it.

I really appreciate your time. I'll probably talk to the host about it after this.

hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

2

I assume ../blog/feed/ is supposed to point to an URL (that probably gets rewritten by mod_rewrite).

If you use a relative path inside the script, they are going to be treated as physical (filesystem) paths relative to where the script runs, not relative to the URL that is called in the browser.

Specifying a full URL starting with http:// should help.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I would use the http://, but there is a server configuration that I do not have the authority to change preventing that. "URL file-access is disabled in the server configuration". So I'm guessing it needs to be relative in some way. The strange thing is if I manually put an xml file in the same directory and use that, it works. So ../blog/rss.xml works. But I'd rather not have to update manually. – Joseph McCullough Jan 05 '11 at 05:24
  • @Joseph then you'd have to find the correct file path to use. As said, `/blog/feed` is a virtual URL, it doesn't exist on filesystem level. It might be worth a separate question to find that out – Pekka Jan 05 '11 at 10:37
  • @Joseph also check out whether this answer helps to go a different route http://stackoverflow.com/questions/2055725/pull-data-from-wordpress/2056058#2056058 – Pekka Jan 05 '11 at 10:37