例如我使用这个:
对于电子邮件模板:
电子邮件.tpl:
hello {username},
your password is: {password}
解析器.php
function parse(){
$message = file_get_contents("email.tpl");
$patterns[0] = "/\{username\}/";
$patterns[1] = "/\{password\}/";
$replacements = array();
$replacements[0] = $username;
$replacements[1] = $password;
return preg_replace($patterns, $replacements, $message);
}
对于 html 模板:html.tpl:
<b>hello {username}</b>,
<p>your password is: {password}</p>
解析器.php
function parse(){
$message = file_get_contents("html.tpl");
$patterns[0] = "/\{username\}/";
$patterns[1] = "/\{password\}/";
$replacements = array();
$replacements[0] = $username;
$replacements[1] = $password;
return preg_replace($patterns, $replacements, $message);
}
这是最好的方法还是有更好的方法?