PHP sprintf转义%

我想要以下输出:

将从您的充值帐户中扣除27.59欧元的50%。

当我做这样的事情:

$variablesArray[0] = '€'; $variablesArray[1] = 27.59; $stringWithVariables = 'About to deduct 50% of %s %s from your Top-Up account.'; echo vsprintf($stringWithVariables, $variablesArray); 

但它给了我这个错误vsprintf() [function.vsprintf]: Too few arguments in ...因为它认为%50%也replace。 我如何逃避它?

用另一个%转义它:

 $stringWithVariables = 'About to deduct 50%% of %s %s from your Top-Up account.'; 

这很容易。

在原来的%放置另一个%来逃避它。

例如,

 $num=23; printf("%%d of 23 = %d",$num); 

输出:

 %d of 23 = 23 

那这个呢:

 $variablesArray[0] = '%'; $variablesArray[1] = '€'; $variablesArray[2] = 27.59; $stringWithVariables = 'About to deduct 50%s of %s %s from your Top-Up account.'; echo vsprintf($stringWithVariables, $variablesArray); 

只需在variables数组中添加百分号