Merge pull request #2 from raamdev/master

Fallback to cURL if allow_url_fopen disabled in PHP configuration
This commit is contained in:
Ismo Vuorinen
2013-07-26 02:40:59 -07:00

View File

@@ -20,7 +20,24 @@
}
$feed = "http://xkcd.com/atom.xml";
$data = simplexml_load_file($feed);
// Check if http:// wrapper is allowed
if( ini_get('allow_url_fopen') ) {
$data = simplexml_load_file($feed);
} else {
// If http:// wrapper is disabled (by allow_url_fopen=0, for example), then fall back on cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feed);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result = curl_exec($ch);
curl_close($ch);
$data = simplexml_load_string($result);
}
$item = $data->entry[0];
$date = date("Y-m-d", strtotime($item->updated));
preg_match("#title=\"(.+)\"#iU", $item->summary, $t);