As I know, we can set
error_reporting = E_ERROR
display_errors = Off
in php.ini, for a globe setting.
But I only want to cancel an errors notice in one PHP file, not all the pages. when something will print in the page like:
Warning: getimagesize(CU1402715579480Bv-300x286--50x50.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported...
Can we close an errors notice on the page, like <php set_time_limit(0); ?>
<php set_time_limit(0); ?>
or <php date_default_timezone_set('America/Los_Angeles'); ?>
<php date_default_timezone_set('America/Los_Angeles'); ?>
Yes, see
error_reporting()
to suppress the error
error_get_last()
to get the error message afterwards if necessary
Related: The error handling functions chapter in the manual.
Yes you can, see example:
if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}
Please read:
Besides setting error_reporting(E_ERROR)
in the script, you can also individually suppress errors for specific functions using the shut up operator:
@getimagesize("http://wrong.wrong.wrg/nonexist.png");
Though in your case you might want to set protocol_version
by requesting the file separataly with http context options, http://www.php.net/manual/en/context.http.php - this would eliminate the actual error. (Or as lazy alternative use a HTTP class/library.)
In your specific script, which generate the notice, you can put this:
error_reporting(E_ALL ^ E_NOTICE);
All the error (E_ALL) except notices (E_NOTICE) will be shown.
Aka.
error_reporting(E_ALL ~E_NOTICE); maybe a syntax error over here i'm not pretty sure though
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.