欢迎各位兄弟 发布技术文章
这里的技术是共享的
1.在php.ini文件中改动error_reporting
如果你不能操作php.ini文件,你可以用下面的方法来实现
2.在你想禁止notice错误提示的页面中加入下面的代码
/* Report all errors except E_NOTICE */
error_reporting(E_ALL ^ E_NOTICE);
希望上面的代码能解决你的问题。
这个还好一些,让你知道怎么搞!打开php.ini,ctrl+f找到error_reporting,把上面的ctrl+v过来,浏览自己的网页,诶,真的不显示php notice了,这时真是对这位大哥感激的不行啊,终于帮我们这些菜鸟们解决问题了。
但是,不要急着关闭php.ini,让我们好好看看我们的php.ini:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; error_reporting is a bit-field.
; reporting level
; E_ALL
; E_ERROR
; E_RECOVERABLE_ERROR
; E_WARNING
; E_PARSE
; E_NOTICE
;
;
;
;
; E_STRICT
;
;
; E_CORE_ERROR
; E_CORE_WARNING
;
; E_COMPILE_ERROR
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR
; E_USER_WARNING
; E_USER_NOTICE
;
; Examples:
;
;
;
;error_reporting = E_ALL & ~E_NOTICE
;
;
;
;error_reporting = E_ALL & ~E_NOTICE | E_STRICT
;
;
;
;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
;
;
;
error_reporting
虽然是英文的,但是就这么几个英文单词,应该难不倒我们吧!
看完,你会发觉,搜索出来的解决办法似乎不大好,而应该这样:
去掉;error_reporting = E_ALL & ~E_NOTICE这一句全面的;就可以了。
这样做比搜索出来的解决办法简单,而且这样做还保证了php.ini的完整性。
现在,再来看看在网页中对错误报告级别的控制吧!
拿出你的php手册,索引->error_reporting,看到了吧!
The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.
The new error_reporting level. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions. As error levels are added, the range of integers increases, so older integer-based error levels will not always behave as expected.
The available error level constants are listed below. The actual meanings of these error levels are described in the predefined constants.
| value | constant |
|---|---|
| 1 | E_ERROR |
| 2 | E_WARNING |
| 4 | E_PARSE |
| 8 | E_NOTICE |
| 16 | E_CORE_ERROR |
| 32 | E_CORE_WARNING |
| 64 | E_COMPILE_ERROR |
| 128 | E_COMPILE_WARNING |
| 256 | E_USER_ERROR |
| 512 | E_USER_WARNING |
| 1024 | E_USER_NOTICE |
| 2047 | E_ALL |
| 2048 | E_STRICT |
| 4096 | E_RECOVERABLE_ERROR |
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>又是英文,不过也简单,看看这个范例就知道怎么做了吧!
来自 http://blog.sina.com.cn/s/blog_580c01cf010008y6.html