[英]content change dynamic with variable in php
Hi guys i have sending a message to customer mobile like this 嗨,大家好,我已经像这样向客户手机发送了一条消息
$message="Your ticket is booked for ID='$id'";
So now my boss tell me that we need a provision to customize this message.may be like this 所以现在老板告诉我,我们需要一项条款来自定义此消息。
$message="Your ticket ID='$id' is booked,you are welcome";
They will change the message simultaneously. 他们将同时更改消息。 So i add a part in admin to change that message using text area.But what i do with that variable $id
? 所以我在管理员中添加了一部分以使用文本区域更改该消息。但是我如何处理变量$id
? How i add variable to database and fetch that? 我如何将变量添加到数据库并获取该变量?
Save your message in database like this 像这样将您的消息保存在数据库中
$message="Your ticket ID= ###id### is booked,you are welcome";
And while getting the data from database 在从数据库获取数据的同时
$message = //message from db
str_replace("###id###", $id, $message);
Hope it helps 希望能帮助到你
Cheers 干杯
My suggestion would be to use a placeholder for that. 我的建议是为此使用占位符。 As input, you could for instance define a %ID%
placeholder, and replace that dynamically when you retrieve the message from your database. 作为输入,您可以例如定义%ID%
占位符,并在从数据库中检索消息时动态替换它。
For example, when your boss enters the message "Your ticket is booked for ID=%ID%"
, you replace %ID%
with the real ID in your PHP script. 例如,当老板输入消息"Your ticket is booked for ID=%ID%"
,您将%ID%
替换为PHP脚本中的真实ID。
$message="Your ticket ID = {{ id }}is booked,you are welcome";
$message = str_replace("{{ id }}", $id, $message);
echo $message;
Here I suggesting the same as vaibhav but more visible format 在这里,我建议与vaibhav相同,但格式更明显
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.