Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created December 2, 2014 07:02
Show Gist options
  • Save violetyk/97eed8a62e7aa9a133db to your computer and use it in GitHub Desktop.
Save violetyk/97eed8a62e7aa9a133db to your computer and use it in GitHub Desktop.
file_get_contents()エラー判定
<?php
$context = stream_context_create(array(
'http' => array(
'ignore_errors' => true,
'header' => 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
)
));
$response = file_get_contents($url, false, $context);
$pos = strpos($http_response_header[0], '200');
if ($pos === false) {
echo 'error';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment