Help with my PHP template class -


i want separate output of html program code in projects, wrote simple database class.

<?php class template {     private $template;      function load($filepath)     {         if(!$this->template = file_get_contents($filepath))             $this->error('error: failed open <strong>' . $filepath . '</strong>');     }      function replace($var, $content)     {         $this->template = str_replace("{$var}", $content, $this->template);     }      function display()     {         echo $this->template;     }      function error($errormessage)     {         die('die() template class: <strong>' . $errormessage . '</strong>');     } } ?> 

the thing need display() method. example use code:

$tplobj = new template(); $tplobj->load('index.php'); $tplobj->replace('{title}', 'homepage'); $tplobj->display(); 

and index.php file this:

<html>     <head>         <title>{title}</title>     </head>     <body>         <h1>{title}</h1>         <?php             if($something) {                 echo '$something true';             } else {                 echo '$something false';             }         ?>     </body> </html> 

i'm wondering if php code in there run? or sent browser plaintext? using eval() in template class hate function :p

thanks.

no. come out plain text.

'echo' outputs without parsing php code.

you don't need fall on using eval. there other ways example using output buffering.


Comments