-
-
Save septor/ca750ceb18cf41716de05ddc0447c5c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* @param string $url The URL to fetch | |
* @param boolean $json if true, returns decoded json array | |
* @param boolean $show_error if true, prints curl error to screen | |
* @author CodeBrauer <https://github.com/CodeBrauer> | |
* @return string result of fetched url, false on failure | |
*/ | |
function curl_get_contents($url, $json = false, $show_error = false) { | |
if (!function_exists('curl_init')) { return file_get_contents($url); } // fallback | |
$ch = curl_init(); | |
$options = array( | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => $url, | |
CURLOPT_HEADER => false, | |
); | |
curl_setopt_array($ch, $options); | |
$response = curl_exec($ch); | |
if ($response === false && $show_error) { | |
echo 'ERROR: ' . curl_error($ch)."\n"; | |
} | |
curl_close($ch); | |
if ($json) { | |
return json_decode($response, true); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment