2012-01-23 189 views
-7

正如标题指出:有没有办法阻止html警告?

Warning: getimagesize failed to open, etc 

有没有办法忽略这些,意味着不打印出来?原因是,我基本上不关心,他们是非常罕见的,我在测试显然做的,但如果这样做了,我宁愿设置代码给我发电子邮件比闪了大丑的信息给用户。

问题适用于由任何方式警告。

+7

关闭php.ini中的'display_errors'或在代码中执行'ini_set('display_errors',0)''。但是,真的,你应该修复代码,使它们不在第一位发布。 –

+2

请参阅http://docs.php.net/manual/en/function.error-log.php,了解如何配置电子邮件日志记录 – Gordon

+0

您可以编辑您的php.ini,并禁用'display_errors'或更改'error_reporting'不显示警告。我不太记得确切的设置,但你可以在php.ini上找到它。无论如何,你应该尝试修复这些错误:) – jere

回答

1

他们是PHP错误,你可以通过改变你的PHP INI设置将其关闭,搜索display_errors

display_errors = Off

6

有几种不同的方式:

  • 设置一个custom error handler(最好的方法,让你做一些有用的东西像电子邮件的错误,而你自己)
  • ini_set('display_errors', false);
  • 完全
  • Surpress错误通过@操作:@getimagesize(...);
2

许多方面存在着,这里有几个...

error_reporting(0); //Will hide all errors from hapenning 

最终,你只能关闭E_WARNING但这需要一些布尔数学从当前的error_reporting()设置中仅排除E_WARNING。

另一种方法是把一个@符号在你想隐藏的错误操作的面前:

$returnvalue = @getimagesize($params); 

这将防止错误显示...

最后的办法是关闭错误显示使用:

ini_set('display_errors', 0); 

但这样,所有错误,警告,通知都被隐藏。他们仍然登录到错误日志文件。

最后警告我可能想给你的是,从来没有与具有错误的可能性代码。总有一些验证可以做,应该做。关闭错误或忽略它们通常是不好的,当你尝试修复,并且出现是因为你决定简单地隐藏潜在的错误问题,可能会导致艰辛后..

好运

0

我假设有这里涉及一些PHP。您可以通过配置您的php.ini(php配置文件)文件来更改错误报告。您可以关闭错误报告功能,将其留作警告和通知,将其保留在错误状态或让其保持全部状态。

通知和警告不会造成大问题,或从运行保持脚本。致命错误虽然会阻止脚本运行。

所以你的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

您可以使用您的网页error_reporting(0);

,或者您也可以使用.htaccess文件和php.ini设置错误报告了。

相关问题