最近在寫php的過程當中發現php提示php notice:………………的字樣,雖然這個只是php的提示內容,並無什麼大的影響,可是出於安全性和美觀方面的考慮,小弟仍是想把這個東西去掉。 那麼,怎麼辦呢? 擡出baidu,直接複製、粘貼php notice:,這樣搜索的結果,通常有兩種狀況: 1、直接來一句:error_reporting=E_ALL&~E_NOTICE,搞得你不知道什麼意思?! 2、 1.在php.ini文件中改動error_reporting 改成: error_reporting=E_ALL&~E_NOTICE 若是你不能操做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. Or each number up to get desired error ; reporting level ; E_ALL - All errors and warnings (doesn't include E_STRICT) ; E_ERROR - fatal run-time errors ; E_RECOVERABLE_ERROR - almost 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_STRICT - run-time notices, enable to have PHP suggest changes ; to your code which will ensure the best interoperability ; and forward compatibility of your code ; 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 ; ; Examples: ; ; - Show all errors, except for notices and coding standards warnings ; ;error_reporting = E_ALL & ~E_NOTICE ; ; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE | E_STRICT ; ; - Show only errors ; ;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR ; ; - Show all errors, except coding standards warnings ; error_reporting = E_ALL 雖然是英文的,可是就這麼幾個英文單詞,應該難不倒咱們吧! 看完,你會發覺,搜索出來的解決辦法彷佛不大好,而應該這樣: 去掉;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. 參數 level 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. 表82.error_reporting() level constants and bit values 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 返回值 Returns the old error_reporting level. 範例 例543.error_reporting() examples copy to clipboard <?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); ?>