方法有三:
1.@可以屏避代碼中的錯誤,如果此行代碼出錯,用這個@號之後錯誤將不顯示出來。
2.還可以在頁首加上error_reporting(0); 將禁止本頁內任何錯誤顯示。
3.也可以在php.ini中禁止顯示錯誤,display_errors = Off。
- <?php
- //error_reporting(0)
- //display_errors = On
- ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>如何在PHP中,禁止顯示錯誤?</title>
- </head>
- <body>
- <?php
- echo("<p>You typed this:</p>");
- echo("<p>");
- if(@$_POST["myText"]=="")
- {
- echo "對不起!參數傳遞錯誤!";
- }
- else
- {
- echo(htmlentities(@$_POST["myText"]));
- }
- echo("</p>");
- ?>
- </body>
- </html>