Php将单词中的多个部分更改为预定义值
我正在尝试将动态内容添加到HTML以创建动态电子邮件模板 所以在我的HTML中Php将单词中的多个部分更改为预定义值,php,Php,我正在尝试将动态内容添加到HTML以创建动态电子邮件模板 所以在我的HTML中 $html = '<b>Its a html {name} content email {email} here</b>'; 那么,我如何继续,以便附加到HTML主体的最终HTML将是 '<b>Its a html Allan content email al@al.com here' 我希望: $html='这是一封html{name}内容的电子邮件{email}这里
$html = '<b>Its a html {name} content email {email} here</b>';
那么,我如何继续,以便附加到HTML主体的最终HTML将是
'<b>Its a html Allan content email al@al.com here'
我希望:
$html='这是一封html{name}内容的电子邮件{email}这里';
$arraydata=[“姓名”=>“艾伦”,“电子邮件”=>“al@al.com"];
foreach($arraydataas$key=>$value){
$html=str_replace('{.$key.'}',$value$html);
}
返回$html;
返回值为:
“这是一封html Allan内容电子邮件al@al.com这里“
在这种情况下,我会
$arraydata = ["name"=>"Allan","email"=>"al@al.com"];
echo $html = '<b>Its a html '. $arraydata['name'].' content email '. $arraydata['email'].' here</b>';
$arraydata=[“name”=>“Allan”,“email”=>”al@al.com"];
echo$html='这是一个html'$arraydata['name'].“内容电子邮件”$arraydata[“电子邮件”]。“此处”;
输出:这是一封html Allan内容电子邮件al@al.com此处您可以使用以下代码,如果占位符出现多种外观,则将替换这些代码,如下所示:
var replaceAll = function(string, replacingItem, replaceWith) {
return string.toString().replace(new RegExp(replacingItem, 'g'), replaceWith);
};
$html = '<b>Its a html {name} content email {email} here</b>';
$arraydata = ["name"=>"Allan","email"=>"al@al.com"];
foreach ($arraydata as $key => $value) {
$html = replaceAll($html, '{' . $key . '}', $value);
}
return $html;
var replaceAll=function(字符串、replacingItem、replaceWith){
返回字符串.toString().replace(新的RegExp(replacingItem,'g'),replaceWith);
};
$html='这是一封html{name}内容的电子邮件{email}这里';
$arraydata=[“姓名”=>“艾伦”,“电子邮件”=>“al@al.com"];
foreach($arraydataas$key=>$value){
$html=replaceAll($html,{.$key.'}',$value);
}
返回$html;
希望对你有帮助
$arraydata = ["name"=>"Allan","email"=>"al@al.com"];
echo $html = '<b>Its a html '. $arraydata['name'].' content email '. $arraydata['email'].' here</b>';
var replaceAll = function(string, replacingItem, replaceWith) {
return string.toString().replace(new RegExp(replacingItem, 'g'), replaceWith);
};
$html = '<b>Its a html {name} content email {email} here</b>';
$arraydata = ["name"=>"Allan","email"=>"al@al.com"];
foreach ($arraydata as $key => $value) {
$html = replaceAll($html, '{' . $key . '}', $value);
}
return $html;