Fri, 17 May 2024


How to define an own error handling function for PHP to use instead of its default?

By: Peter, NetArt Media
Fri, 5 February 2021

string set_error_handler ( string error_handler)

Example:

<?php

function my_error_handler ($errno, $errstr, $errfile, $errline, $errcontent)
{
echo "<font color='red'><b>An Error Occured!</b></font><br>";
echo "<b>Error Number:</b> $errno<br>";
echo "<b>Error Description:</b> $errstr<br>";
echo "<b>Error In File:</b> $errfile<br>";
echo "<b>Error On Line:</b> $errline<br>";
}

set_error_handler("my_error_handler");

$x = 5/0;

?>


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox