Php 将变量存储为数据库中的变量?

Php 将变量存储为数据库中的变量?,php,html,variables,Php,Html,Variables,我将一些电子邮件存储在数据库中,因为它们是模板,我希望管理员能够编辑它们。所以有三列,initialmail,followup,followup2。但是,这些模板如下所示: Hello $Client, we are contacting you about your $product $replaceWord = array( "[name]" => $row['username'], "[age]" => $row['age'], ); $emailCont

我将一些电子邮件存储在数据库中,因为它们是模板,我希望管理员能够编辑它们。所以有三列,initialmail,followup,followup2。但是,这些模板如下所示:

Hello $Client, we are contacting you about your $product 
$replaceWord = array(
    "[name]" => $row['username'],
    "[age]" => $row['age'],
);

$emailContent = strtr($emailContentDatabase, $replaceWord); //notice $emailContentDatabase is what there is saved in the database.
Welcome [name],

Your age is: [age].
之后,“发送邮件”将从右栏中随机选取一行并发送。但是,我不知道如何使管理员能够添加/编辑电子邮件,并在数据库中存储变量名,而不是值,因此sendmail.php将知道存在哪些变量,并用正确的值替换它们。请记住,这需要很简单,因为管理员会在站点上编辑此内容,所以我不能让他们键入“
”。$Clientname。”都会


谢谢大家!

您可以这样做:

Hello $Client, we are contacting you about your $product 
$replaceWord = array(
    "[name]" => $row['username'],
    "[age]" => $row['age'],
);

$emailContent = strtr($emailContentDatabase, $replaceWord); //notice $emailContentDatabase is what there is saved in the database.
Welcome [name],

Your age is: [age].
例如,数据库中的电子邮件如下所示:

Hello $Client, we are contacting you about your $product 
$replaceWord = array(
    "[name]" => $row['username'],
    "[age]" => $row['age'],
);

$emailContent = strtr($emailContentDatabase, $replaceWord); //notice $emailContentDatabase is what there is saved in the database.
Welcome [name],

Your age is: [age].
然后,使用上面的脚本将输出如下内容

Welcome Perry,

Your age is: 45.

您可以这样做:

Hello $Client, we are contacting you about your $product 
$replaceWord = array(
    "[name]" => $row['username'],
    "[age]" => $row['age'],
);

$emailContent = strtr($emailContentDatabase, $replaceWord); //notice $emailContentDatabase is what there is saved in the database.
Welcome [name],

Your age is: [age].
例如,数据库中的电子邮件如下所示:

Hello $Client, we are contacting you about your $product 
$replaceWord = array(
    "[name]" => $row['username'],
    "[age]" => $row['age'],
);

$emailContent = strtr($emailContentDatabase, $replaceWord); //notice $emailContentDatabase is what there is saved in the database.
Welcome [name],

Your age is: [age].
然后,使用上面的脚本将输出如下内容

Welcome Perry,

Your age is: 45.

而且。。。你的问题到底是什么?你在哪里挣扎?我不知道如何将它存储在数据库中。如果管理员可以写一封像“Hello USERNAME”这样的电子邮件,php会将其翻译成
$USERNAME
,并将其作为
$USERNAME
存储在数据库中,那就太好了。或者在写电子邮件插入变量时不需要太多麻烦的任何其他方式。谢谢,这回答了我问题的第二部分,我仍然不知道如何将此
$USERNAME
存储在数据库中,作为
$USERNAME
。为什么不直接将用户输入目录存储在数据库中,然后在发送电子邮件时替换模板?为什么不使用类似“###用户名###”的东西并用脚本替换它?然后。。。你的问题到底是什么?你在哪里挣扎?我不知道如何将它存储在数据库中。如果管理员可以写一封像“Hello USERNAME”这样的电子邮件,php会将其翻译成
$USERNAME
,并将其作为
$USERNAME
存储在数据库中,那就太好了。或者在写电子邮件插入变量时不需要太多麻烦的任何其他方式。谢谢,这回答了我问题的第二部分,我仍然不知道如何将此
$USERNAME
存储在数据库中,作为
$USERNAME
。为什么不直接将用户输入目录存储在数据库中,然后在发送电子邮件时替换模板?为什么不使用类似“###用户名###”的东西并用脚本替换它?我的代码太长,无法在此处发布,但它的工作方式与您所说的完全相同。我甚至分配了一些在脚本中计算出来的变量来替换,比如
“[price]”=>$price,
,它可以正常工作。谢谢!听到它起作用我很高兴!:)我的代码太长,无法在这里发布,但它的工作原理与您所说的完全一致。我甚至分配了一些在脚本中计算出来的变量来替换,比如
“[price]”=>$price,
,它可以正常工作。谢谢!听到它起作用我很高兴!:)