我在PHP中使用sprintf()
但它在页面上没有显示任何内容。
这就是我正在做的事情:
$lang['request_paragraph']="Please check your email for a message from %s (%s). This message contains instructions for initiating the issuance of a new password for your participant number. If you did not receive the email message from %s within 10-15 minutes, please make sure that your email provider does not have a spam filter that is blocking our email from reaching your Inbox. You will not be able to receive email from us if your email provider is using a mail-blocking device. Click on the button below to send the validation email again if it appears to have been blocked or never received. You will only be able to re-send the validation email 3 more times.";
$company="Company Name";
$admin_email="admin@company.com";
sprintf($lang['request_paragraph'],$company,$admin_email,$company);
对每个字符串执行回显正确显示每个字符串,那么我做错了什么?
我需要使用sprintf()
,因为我正在处理语言文件,这比将段落分成语言定义中的部分要简单得多。
答案 0 :(得分:6)
sprintf返回一个变量(一个字符串)。
你需要printf
答案 1 :(得分:0)
修改为echo sprintf($lang['request_paragraph'],$company,$admin_email,$company);
答案 2 :(得分:0)
你也需要回应 sprintf 。
答案 3 :(得分:0)
sprintf 函数只是在第一个字符串参数中顺序替换占位符(类型说明符)字符,并且不回显,打印或输出任何内容,只返回格式化字符串。
所以你的代码行:
sprintf($lang['request_paragraph'],$company,$admin_email,$company);
将替换为:
echo sprintf($lang['request_paragraph'],$company,$admin_email,$company);
或
print(sprintf($lang['request_paragraph'],$company,$admin_email,$company));