Forum Moderators: coopster

Message Too Old, No Replies

how to parse template file?

         

PHPycho

11:26 am on Aug 29, 2007 (gmt 0)

10+ Year Member



Hello forums!
I have some file named "test.tpl"
whic has following contents
"Hello %name% your passwrod is %passwrod%"
I would like to call this file and replace those values within % with dynamic values(may also {}).
Any comments and suggestions are warmly welcome.
Thanks in advance to all of you

vincevincevince

12:14 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$values['name']="John";
$values['password']="sex";

$text=file_get_contents("template.html");
$text=preg_replace("/\%([^\% ]+)\%/e","$values[$1]",$text);
print $text;