How to output error message in php

藏色散人
Release: 2023-03-13 11:46:01
Original
4524 people have browsed it

How to output error prompts in php: 1. Open the corresponding PHP file; 2. Add "error_reporting(E_ALL);"; 3. Output the error message through the "function cache_shutdown_error() {...}" method That’s it.

How to output error message in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php output an error message?

php output error message

error_reporting(E_ALL);
function cache_shutdown_error() {
          $_error = error_get_last();
          if ($_error && in_array($_error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL)))
{
                    header("Content-Type: text/html; charset=utf-8");
                    echo &#39;<font color=red>你的代码出错了:</font></br>&#39;;
                    echo &#39;致命错误:&#39; . $_error[&#39;message&#39;] . &#39;</br>&#39;;
                    echo &#39;文件:&#39; . $_error[&#39;file&#39;] . &#39;</br>&#39;;
                    echo &#39;在第&#39; . $_error[&#39;line&#39;] . &#39;行</br>&#39;;
                }
            }
 register_shutdown_function("cache_shutdown_error");
Copy after login

It is best to put it at the front. If an error is reported and it terminates, this method cannot be executed.

Recommended study: "PHP video tutorial

The above is the detailed content of How to output error message in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template