How can I show php errors elsewhere

1

When you give me an error for example:

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\sitio\index.php on line 5

I would like it to appear in div or section of html , so that it is not ugly on top of all the content that comes out, you can help me, to be able to style it with css .

    
asked by Cris GO 24.04.2018 в 05:52
source

1 answer

1

I suggest redirecting the "Error Handler":

<?php

function customError($errno, $errstr) {
// Define global variable
    global $err1;
    $err1=  "<b>Error:</b> [$errno] $errstr";
} 

//set error handler
set_error_handler("customError");

//trigger error
echo($test);

echo "111<br>";
echo "222<br>";
echo "333<br>";
echo "444<br>";

echo "<div id='err1'>
</div>";

?>

<script>
window.onload = function(){
//  Guardamos el error en el div con id err1
    document.getElementById('err1').innerHTML="<h1><?php echo $err1; ?></h1>";
}
</script>

the result will be:

111

222

333

444

Error: [8] Undefined variable: test

    
answered by 24.04.2018 / 07:28
source