Created
June 24, 2021 21:22
-
-
Save medeirosinacio/ff223dd8470a8242ee9de3cd29cbe775 to your computer and use it in GitHub Desktop.
PHP If file_get_contents fails, do this instead
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
/** | |
* It's a modified file_get_contents() | |
* get_contents(filename, use_include_path, context, offset, maxlen) | |
* @param $url | |
* @param bool $u | |
* @param null $c | |
* @param null $o | |
* @return bool|string | |
* @package https://stackoverflow.com/questions/8673272/php-if-file-get-contents-fails-do-this-instead | |
*/ | |
function get_contents($url, $u = false, $c = null, $o = null) | |
{ | |
$headers = get_headers($url); | |
$status = substr($headers[0], 9, 3); | |
if ($status == '200') { | |
return file_get_contents($url, $u, $c, $o); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment