2012-07-28 64 views
0

我想打一個功能我laguagesprintf的語言錯誤

使用語言形式的數據庫系統,IM

有些話我必須在腳本redefina,但我不能找到辦法

我的代碼:

$str = "I'm %s from %s"; // string from database 

$tre = 'ex3m,Albania'; // replacements 
$tre = explode(',',$tre); // trying to convert replacements to strings separated with commas 

sprintf($str, $tre); 

resoults:

Warning: sprintf(): Too few arguments 

,我想結果是:

I'm ex3m from Albania 
I'm {ex3m} from {Albania} 

有人能幫助我嗎?

回答

1

sprintf需要可變數量的參數,而不是數組。使用vsprintf

$result = vsprintf($str, $tre); 
+0

日Thnx男人對你有所幫助 – 2012-07-28 14:14:32

+0

@ ex3m.al:沒問題!如果這對你有效,你可以通過點擊左邊的空綠色複選框來接受答案。 – Ryan 2012-07-28 14:24:17