Skip to content

Instantly share code, notes, and snippets.

@medeirosinacio
Created June 24, 2021 21:22
Show Gist options
  • Save medeirosinacio/ff223dd8470a8242ee9de3cd29cbe775 to your computer and use it in GitHub Desktop.
Save medeirosinacio/ff223dd8470a8242ee9de3cd29cbe775 to your computer and use it in GitHub Desktop.
PHP If file_get_contents fails, do this instead
/**
* 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