替换字符串标记的变量
例如:
$mytext = 'Hi, my name is {%name%}, and my address is {%address%}';
rep_templates($mytext, array('name'=>'Steven', 'address'=>'Rua Beira Mar, 12'));
print $text; //输出: Hi, my name is Steven, and my address is Rua Beira Mar, 12
Other ex.
$row = mysql_fetch_assoc($my_result_from_query);
$mytext = file_get_contents('./text_for_email_template.txt');
tranf_dados($mytext, $row);
sendmail($row['email', 'Subject:Hi mane!', $mytext);
function rep_templates(&$t, $d){
preg_match_all ( '/{\%(\w*)\%\}/' , $t , $matches );
foreach($matches[1] as $m){
if($d[$m]!=null){
$pattern = "/{\%".$m."\%\}/";
$t = preg_replace( $pattern, $d[$m], $t);
}
}
}
