I was trying out the simplexml_load_file function for parsing RSS feeds on my hosting server using the following code-
$rss = simplexml_load_file(‘http://naveenbalani.com/index.php/feed/’);
and got the following exception on my hosting server –
“URL file access is disabled in the server configuration”
After googling through the documentation, I noticed that the simple_xml_load uses furl_open function to get files remotely. This function, due to security issues was not supported on my hosting server (and probably most of the hosting providers.)
The option was to use CURL library to parse remote urls , along with simple_xml function. Here is the modified code which should work on most of the hosting servers.
<?php function load_file($url) { $ch = curl_init($url); #Return http response in string curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $xml = simplexml_load_string(curl_exec($ch)); return $xml; } $feedurl = 'http://naveenbalani.com/index.php/feed/'; $rss = load_file($feedurl); foreach ($rss->channel->item as $item) { echo "<h2>" . $item->title . "</h2>"; echo "<p>" . $item->description . "</p>"; } >