【问题标题】:How to assign value to variable that fetched from database?如何为从数据库中获取的变量赋值?
【发布时间】:2023-01-20 17:30:35
【问题描述】:

使用“SELECT”查询从数据库中获取的字符串,其中包含变量名称“Dear $customer_name”在该页面 $customer_name='John Denie' 但在回显中它打印“Dear $customer_name”而不是“Dear John Denie”

/// in brief codding just to clear idea ///
         $customer_name='John Denie'; 
        "SELECT SMS_text From table"   //SMS_text value in database is Dear $customer_name
        $sms_body=$row["SMS_text"];
echo $sms_body

现在这个 $sms_body echo Dear $customer_name 我希望它应该打印 Dear John Denie 根据代码 $customer_name keep changes here I assigned static value forexample。

我尝试了 {} trim 函数和其他方法,但对我没有任何帮助。有任何想法吗?

【问题讨论】:

  • 您是否尝试过使用str_replacetrim() 在这里到底有什么用?

标签: php mysql variables


【解决方案1】:

如果您的短信文本 == '亲爱的 $customer_name ...' 你应该在之后添加行

$sms_body=$row["SMS_text"];

之前

 echo $sms_body:

你应该添加这一行:

 $sms_body= str_replace("$customer_name",$customer_name,$sms_body);   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 2021-04-27
    相关资源
    最近更新 更多