Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 有没有办法停止html警告?_Php_Html - Fatal编程技术网

Php 有没有办法停止html警告?

Php 有没有办法停止html警告?,php,html,Php,Html,正如标题所述: Warning: getimagesize failed to open, etc 有没有办法忽略这些,也就是说不要打印它们?原因是,基本上我不在乎,它们非常罕见,我显然在测试时会这样做,但当测试完成后,我宁愿将代码设置为向我发送电子邮件,也不愿向用户闪现一条丑陋的大消息 顺便提一下,这个问题适用于任何警告。它们是php错误,您可以通过更改php INI设置、搜索显示错误来关闭它们 显示错误=关闭有几种不同的方法: 设置一个最好的方法,让您可以做一些有用的事情,比如将错误通过电

正如标题所述:

Warning: getimagesize failed to open, etc
有没有办法忽略这些,也就是说不要打印它们?原因是,基本上我不在乎,它们非常罕见,我显然在测试时会这样做,但当测试完成后,我宁愿将代码设置为向我发送电子邮件,也不愿向用户闪现一条丑陋的大消息


顺便提一下,这个问题适用于任何警告。

它们是php错误,您可以通过更改php INI设置、搜索显示错误来关闭它们


显示错误=关闭有几种不同的方法:

设置一个最好的方法,让您可以做一些有用的事情,比如将错误通过电子邮件发送给自己 ini_设置“显示错误”,错误; 通过@operator:@getimagesize…,完全超越错误。。。;
存在许多方法,这里有一些

error_reporting(0); //Will hide all errors from hapenning
最终,您只能关闭E_警告,但这需要一些布尔数学来从当前错误报告设置中仅排除E_警告

另一种方法是在要隐藏错误的操作前面加上@符号:

$returnvalue = @getimagesize($params);
这将防止错误显示

最后一种方法是使用以下方法关闭错误显示:

ini_set('display_errors', 0);
但这样,所有错误、警告、通知都被隐藏了。尽管如此,它们仍然被记录到错误日志文件中

我想给你的最后一个警告是,永远不要编写可能出错的代码。总有一些验证你可以做,也应该做。关闭错误或忽略错误通常是不好的,并且可能会导致以后在尝试修复时遇到困难,以及由于您决定简单地隐藏潜在错误而出现的问题


祝你好运

我假设这里涉及到一些PHP。您可以通过在php配置文件中配置php.ini来更改错误报告。您可以关闭错误报告,为警告和通知保持打开状态,为错误保持打开状态,或为所有人保持打开状态

通知和警告不会导致重大问题或阻止脚本运行。但致命错误将阻止脚本运行

因此,在php.ini文件中,查找以下行:

error_reporting=E_error,并将其更改为以下选项之一或以下选项的组合:

E_ALL             - All errors and warnings
E_ERROR           - fatal run-time errors
E_WARNING         - run-time warnings (non-fatal errors)
E_PARSE           - compile-time parse errors
E_NOTICE          - run-time notices (these are warnings which often result
                  from a bug in your code, but it's possible that it was
                  intentional (e.g., using an uninitialized variable and
                  relying on the fact it's automatically initialized to an
                  empty string)
E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
                  initial startup
E_COMPILE_ERROR   - fatal compile-time errors
E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
E_USER_ERROR      - user-generated error message
E_USER_WARNING    - user-generated warning message
E_USER_NOTICE     - user-generated notice message
通过将该值设置为E_ERROR,将不会显示警告和通知。只显示错误。

您可以使用错误报告0


也可以使用file和php.ini关闭错误报告。

关闭php.ini中的显示错误或执行ini设置“显示错误”,0;在你的代码中。但实际上,您应该首先修复代码,使其不被发布。请参阅了解如何配置电子邮件日志。您可以编辑php.ini,禁用显示错误或更改错误报告的值以不显示警告。我不太记得确切的设置,但您可以在php.ini上找到它。无论如何,您应该首先尝试修复这些错误:您还可以使用error_reporting0;在你的PHP脚本中。@Cygal这有多可靠?我尝试过使用error_reporting函数,但大多数时候它似乎都被覆盖了。