有没有办法解决这个Sprintf问题

时间:2019-06-24 18:23:04

标签: php html

我的这段代码可以正常工作,但是会在代码行之后剪切消息:

message=Sprintf("<p>Dear user,<br />
Your request have been initiated from your Account. Enter your code <br /><br />
Your Code is: %u", $data['code'], 
================================================Doesn't send this part below
"Your Code will expire in 30 minutes, 
Thank you for choosing Industrial Bank, we are determined to making life better for you.<br />
<br /><br />
Regards,<br />
Apptix<br />
")

我尝试用有问题的部分创建另一个变量。

message=Sprintf("<p>Dear user,<br />
Your  transfer request have been initiated from your Private Account. Enter your code <br /><br />
Your Code is: %u", $data['code'] <br /> <br /> 
"Your Code will expire in 30 minutes, 
Thank you for choosing Industrial Bank, we are determined to making life better for you.<br />
<br /><br />
Regards,<br />
Apptix<br />
")

2 个答案:

答案 0 :(得分:1)

sprintf()的第一个参数是字符串模板。您正在尝试使用两个单独的模板,这些模板将不起作用。你有:

sprintf('template 1', $data['code'], 'template 2');

您要

sprintf('template 1 template 2', $data['code']);

或者也许:

sprintf('template 1', $data['code']) . 'template2';

答案 1 :(得分:0)

  • 使用美元符号初始化变量
  • 使用sprintf函数而不是Sprintf
  • 使用%s代替%
  • u之后不需要逗号 $ data

    $mesage = sprintf("<p>Dear user,<br />
    Your request have been initiated from your Account. Enter your code <br /><br />
    Your Code is: %s", $data['code']);
    // output  $message
    echo $mesage;
    

之后,$ message变量将使用$ data ['code']内容代替%s