Pregunta

Is there a way to style the output of php's die(); message?

I want to add some HTML and CSS around the error message so that I could use it in a productive environment.

¿Fue útil?

Solución

If you're using the actual die() function, it will always print out exactly what text you pass it (which could be HTML, but might be awkward to use).

You could, however, simply make your own function that prints out an error message nicely and then calls exit - that way you don't have to repeat the HTML that you might otherwise pass to die() every time.

function die_nicely($msg) {
    echo <<<END
<div id="critical_error">$msg</div>
END;
    exit;
}

Otros consejos

<?php
if('1'=='1')
echo '<font color=red>';
die('Its true');
echo 'its false';
?>

   <?php
    if('1'=='1')
   {    
      echo '<font color=red>Itss true too.</font>';
      exit();
   }
    echo 'its false';
    ?>

Both above are working, just to clear your doubts. :)

You can add html to the string you are feeding to die, but even easier is just echoing out the html that you want before you call die.

Yes, you can do like this,

die("<div>Error: ".mysql_error()."</div>");

Why not to change die() to its wrapper?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top