how to evalulate when reading and processing a html/php file -


i trying create template function:

function includeandtemplate($file){     $json = '{"first_name" : "first name", "middle_name" : "middle name"}';     $template_vars = json_decode($json);     $file = file_get_contents($file);     foreach($template_vars $var => $value){         $file = str_replace("{{\$".$var."}}", $value, $file);     }        return $file; } 

my html/php:

<p>{{$first_name}}, {{$middle_name}}</p> 

and works fine.

now happens if have this:

<p>{{$first_name}}, {{$middle_name}}, time <?php echo data("h:i:s"); ?></p> 

the raw php code outputed client

i think looking this:

<?php function includeandtemplate($file){     $json = '{"first_name" : "first name", "middle_name" : "middle name"}';     $template_vars = json_decode($json);      ob_start();     require $file;     $file = ob_get_clean();      foreach($template_vars $var => $value){         $file = str_replace("{{\$".$var."}}", $value, $file);     }        return $file; } 

just include file php code executed , after replace whatever want ro replace.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -