html - How to I make this PHP function more efficient? -


i want find out more efficient way of going function:

<?php function ziperror($title, $desc) {     echo '<style type="text/css">';     echo 'body { margin:0;font-family:arial, sans-serif;font-size:13px;background:#ddd;color:#1a1a1a; }';     echo 'h1 { color:#fff;font-family:arial;font-weight:bold;text-align:center; }';     echo 'h2 { color:#1c1c1c;font-family:arial;font-weight:bold;text-align:center;padding-bottom:4px;border-bottom:1px solid #aaa; }';     echo '#error#head { background:#1c1c1c;padding:10px;;border-bottom:5px solid #fff; }';     echo '#error#content { border:1px solid #aaa;background:#fff;padding:20px;width:780px;margin:30px auto; }';     echo 'p { text-align:center;padding:10px;color:#1a1a1a;font-family:verdana; }';     echo '</style>';     echo '<title>' . $title . '</title>';     echo '<div id="error head"><h1>an error has occurred.</h1></div>';     echo '<div id="error content"><h2>'.$title.'</h2><p>'.$desc.'</p></div>'; } 

this code used throw error. example:

die(ziperror('session not found', 'your session has not been found! please re-login now!')); 

although gets job done, i'm trying learn, therefore want make function more efficient, , not hard coded. ideas?

that's error template, this:

create sparate error tamplate: e.g error.php:

<html>    <head>      <style>       //style here...      </style>      <title><?= $title?></title>    </head>    <body>        //and ...    </body> 

and function:

public function ziperror($title, $desc){     include('error.php'); } 

and usage:

 ... die(ziperror('session not found', 'your session has not been found! please re-login now!')); 

now, can edit/change error template long keep echoing $title , $desc , other parameter want to.


Comments