Jump to content

[SOLVED] Problem with function.simplexml-load-file


bobgreen5s

Recommended Posts

Hello I have recently been using the php function, simplexml_load_file() in order to load an xml file and then display it. It was working perfectly until yesterday when it told me that my php server couldn't find the feed anymore. Here is the code and the resulting error message

 

    
$xml = simplexml_load_file('http://feeds.feedburner.com/ace-bdf');

print_r($xml);

 

Warning: simplexml_load_file(http://feeds.feedburner.com/ace-bdf) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 17

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://feeds.feedburner.com/ace-bdf" in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 17

 

This problem is extremely confusing because I can navigate to the feed (http://feeds.feedburner.com/ace-bdf) with my web browser without any problems. Also it was working perfectly a few days ago but stopped working even though I made zero modifications to the script.

 

Any help would be greatly appreciated.

I'm assuming the function actually requires an XML file, not a feed. To get around this load the feed into a string with file_get_contents and run simplexml_load_string on that

 

 

Working code

<?php
print_r( simplexml_load_string( file_get_contents("http://feeds.feedburner.com/ace-bdf") ) );
?>

Thanks for all the replies. When I try Prismatic's suggested code,

<?php
print_r( simplexml_load_string( file_get_contents("http://feeds.feedburner.com/ace-bdf") ) );
?>

 

This is this the resulting error message:

Warning: file_get_contents(http://feeds.feedburner.com/ace-bdf) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\Program Files\XAMPP\xampp\htdocs\xampp\test\xmlfeed\index2.php on line 16

 

For some reason the php server doesn't think anything exists at the specified url. Its very strange because other feeds work and my feed worked up until a couple days ago.

your feed is there, and it's trying to call it, but unable to reach it. May be an issue with your hosting.  Contact them, and see if they can reach that site from their servers (ask them to do a wget for that file on the same server you're hosted on. have them run this exact code:

 

wget http://feeds.feedburner.com/ace-bdf

Here you go, requires CURL lib.

 

Modified from: http://us.php.net/manual/en/ref.curl.php#78046

<?php
$url = 'http://feeds.feedburner.com/ace-bdf';

function disguise_curl($url)
{
  $curl = curl_init();
  $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  $header[] = "Cache-Control: max-age=0";
  $header[] = "Connection: keep-alive";
  $header[] = "Keep-Alive: 300";
  $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  $header[] = "Accept-Language: en-us,en;q=0.5";
  $header[] = "Pragma: "; // browsers keep this blank.

  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_TIMEOUT, 10);

  $html = curl_exec($curl);
  curl_close($curl);

  return $html;
}

print_r( simplexml_load_string( disguise_curl($url) ) );
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.