views:

58

answers:

2

Wordpress is rendering an RSS feed at http://myurl.com/feed/rss/ but of course there's not actually a file there. I'm writing a script to read and render the RSS, but loading the "file" as XML fails, because there's not actually a file there. I write:

$rss = simplexml_load_file('/news/feed/rss/');

And I get this error:

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "/news/feed/rss/"

Even using file_get_contents gives me this error:

Warning: file_get_contents(/news/feed/rss/) [function.file-get-contents]: failed to open stream: No such file or directory
+2  A: 

The file isn't there because the url is being redirected, but you're trying to access it as a file. Assuming you have the correct fopen wrappers (and everyone does), try opening the url with simplexml:

$rss = simplexml_load_file('http://myurl.com/news/feed/rss/');
adam
This sounds like the best solution, Thanks. Tho the host for this web site says, "URL file-access is disabled in the server configuration". So I'm arguing with that now.
Corey Maass
That's odd, I've never come across a host that has disabled fopen wrappers
adam
Bah, it's for the best. Go to a WordPress support forum and ask how to get its RSS. There's certainly a function that will return it for you, and it won't incur the performance penalty of handling an extra HTTP request.
Josh Davis
A: 

The best way is to use Curl ( http://us2.php.net/manual/en/book.curl.php ) for loading external content because you can manipulate with headers etc., it also supports redirects etc.

For example, if mod_security is installed on apache - you wouldn't be able to grab content without passing user-agent header etc., but Curl will definately will help with it.

Kirzilla
You can also set headers with fopen wrappers using stream contexts, negating the need for curl. Besides, the OP doesn't require any headers.
adam
Sorry, but what is "OP"?
Kirzilla
Original Poster. And I second that comment, you seldom need to use curl. The HTTP wrapper lets you do pretty much anything. http://docs.php.net/manual/en/context.http.php
Josh Davis
Thank you! I didn't know about HTTP Wrapper.
Kirzilla