2012-03-27 147 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));