2012-03-27 93 views
1

我在PHP中使用sprintf(),但它在页面上什么都不显示。为什么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="[email protected]"; 

sprintf($lang['request_paragraph'],$company,$admin_email,$company); 

每个单独的字符串显示中做正确的回声每个字符串,所以我究竟做错了什么?

我需要使用sprintf(),因为我正在处理语言文件,它使得它比在语言定义中将段落分割成块更加简单。

+0

哪里的代码显示的东西:

sprintf($lang['request_paragraph'],$company,$admin_email,$company); 

将被替换? – 2012-03-27 10:23:09

回答

6

sprintf返回一个变量(一个字符串)。

你需要的printf

+2

哦。好。现在我感到很傻。我实际上在其他语言文件中使用了printf,不知道如何或为什么我在工作中切换到sprintf。现在就工作,谢谢。 – jovan 2012-03-27 10:24:56

0

编辑echo sprintf($lang['request_paragraph'],$company,$admin_email,$company);

+0

echo sprintf()是printf()的同义词, – Pete 2012-03-27 10:24:09

0

您需要呼应的sprintf了。

0

sprintf函数只是在第一个字符串参数中顺序替换占位符(类型说明符)字符,并且不会回显,打印或输出任何内容,而是返回格式化的字符串。

所以你的代码行:

echo sprintf($lang['request_paragraph'],$company,$admin_email,$company); 

print(sprintf($lang['request_paragraph'],$company,$admin_email,$company)); 
相关问题