Php 从数据库转换文本
我的数据库中有这样一个电子邮件模板:Php 从数据库转换文本,php,Php,我的数据库中有这样一个电子邮件模板: <p style='font-size: 14px; line-height: 14px;'> Gentile {name} la password del tuo account è stata modificata correttamente.<br/> Di seguito i tuoi nuovi dati di accesso: </p> <table>
<p style='font-size: 14px; line-height: 14px;'>
Gentile {name} la password del tuo account è stata modificata correttamente.<br/>
Di seguito i tuoi nuovi dati di accesso:
</p>
<table>
<tr>
<td style='width: 70px'>Username: </td>
<td style='width: 70px'>{$email}</td>
</tr>
<tr>
<td style='width: 70px'>Password: </td>
<td style='width: 70px'>{password}</td>
</td>
</table>
<p style='font-size: 14px; line-height: 14px;'>
A presto<br/>
Lo staff di {APP_NAME}
</p>
试试这个:
$text = str_replace($key, $value, $text);
return $text;
您将
str\u replace
的结果存储在$str
中,因此您只返回我创建此函数的最后一个元素
public function MsgHTML($message, $data=array())
{
if (!empty($data)) {
foreach ($data as $key => $val) {
$message = str_replace('{'.$key.'}', $val, $message);
}
}
return message;
}
试试这个;) 您不需要循环,因为可以使用数组:
function transform($text, $replace) {
if (is_array($replace)) {
return str_replace(arrar_keys($replace), $replace, $text);
} else {
return null;
}
}
function transform($text, $replace) {
if (is_array($replace)) {
return str_replace(arrar_keys($replace), $replace, $text);
} else {
return null;
}
}