0

我想为我的语言做一个功能

我正在使用语言表格数据库系统

有些词我必须在脚本中重新定义,但我找不到方法

我的代码:

$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);

结果:

Warning: sprintf(): Too few arguments

我想要的结果是:

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

有人可以帮助我吗?

4

1 回答 1

1

sprintf接受可变数量的参数,而不是数组。使用vsprintf

$result = vsprintf($str, $tre);
于 2012-07-28T14:06:55.597 回答