Created
October 7, 2011 19:06
-
-
Save mrclay/1271106 to your computer and use it in GitHub Desktop.
file_get_contents with fallback to cURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fetchUrl($url) { | |
$allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen')); | |
if ($allowUrlFopen) { | |
return file_get_contents($url); | |
} elseif (function_exists('curl_init')) { | |
$c = curl_init($url); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
$contents = curl_exec($c); | |
curl_close($c); | |
if (is_string($contents)) { | |
return $contents; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment