Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用变量动态更改内容_Php_Mysql_Mysqli_Textarea - Fatal编程技术网

在php中使用变量动态更改内容

在php中使用变量动态更改内容,php,mysql,mysqli,textarea,Php,Mysql,Mysqli,Textarea,嗨,伙计们,我向客户手机发送了这样的信息 $message="Your ticket is booked for ID='$id'"; $message="Your ticket ID='$id' is booked,you are welcome"; $message="Your ticket ID= ###id### is booked,you are welcome"; 所以现在我的老板告诉我,我们需要一个条款来定制这个消息 $message="Your ticket is b

嗨,伙计们,我向客户手机发送了这样的信息

$message="Your ticket is booked for ID='$id'";
 $message="Your ticket  ID='$id' is booked,you are welcome";
$message="Your ticket  ID= ###id### is booked,you are welcome";
所以现在我的老板告诉我,我们需要一个条款来定制这个消息

$message="Your ticket is booked for ID='$id'";
 $message="Your ticket  ID='$id' is booked,you are welcome";
$message="Your ticket  ID= ###id### is booked,you are welcome";
他们将同时更改消息。
因此,我在admin中添加了一个部分,以使用文本区域更改该消息。但是我如何处理该变量
$id
?如何将变量添加到数据库并获取该变量?

将您的消息保存在数据库中,如下所示

$message="Your ticket is booked for ID='$id'";
 $message="Your ticket  ID='$id' is booked,you are welcome";
$message="Your ticket  ID= ###id### is booked,you are welcome";
在从数据库获取数据的同时

$message = //message from db

str_replace("###id###", $id, $message);
希望能有帮助


干杯

像这样在数据库中保存您的消息

$message="Your ticket is booked for ID='$id'";
 $message="Your ticket  ID='$id' is booked,you are welcome";
$message="Your ticket  ID= ###id### is booked,you are welcome";
在从数据库获取数据的同时

$message = //message from db

str_replace("###id###", $id, $message);
希望能有帮助


干杯

我的建议是使用占位符。例如,作为输入,您可以定义一个
%ID%
占位符,并在从数据库检索消息时动态替换该占位符


例如,当您的老板输入消息“您的票是为ID=%ID%预订的”时,您将在PHP脚本中用真实ID替换
%ID%

我的建议是使用占位符。例如,作为输入,您可以定义一个
%ID%
占位符,并在从数据库检索消息时动态替换该占位符

$message="Your ticket  ID = {{ id }}is booked,you are welcome";
$message = str_replace("{{ id }}", $id, $message);
echo $message;
例如,当您的上司输入消息“您的机票已预订ID=%ID%”,您将在PHP脚本中用真实ID替换
%ID%

$message="Your ticket  ID = {{ id }}is booked,you are welcome";
$message = str_replace("{{ id }}", $id, $message);
echo $message;
在这里,我建议使用与vaibhav相同但更可见的格式


在这里,我建议与vaibhav相同,但格式更为可见。

。可能需要编辑处理该消息的php文件。@marinedea喜欢什么编辑?。可能需要编辑处理该消息的php文件。@marinedea喜欢什么编辑?$message=“您的票证ID=%s已预订,欢迎您”;然后使用sprintf()?$message=“您的票证ID=%s已预订,欢迎您”;然后使用sprintf()?