San*_*ath 167 php printf escaping
我想要以下输出: -
即将从您的充值帐户中扣除50%的27.59欧元.
当我做这样的事情: -
$variablesArray[0] = '€';
$variablesArray[1] = 27.59;
$stringWithVariables = 'About to deduct 50% of %s %s from your Top-Up account.';
echo vsprintf($stringWithVariables, $variablesArray);
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误vsprintf() [function.vsprintf]: Too few arguments in ...,因为它认为%在50%还进行更换.我怎么逃避它?
Bol*_*ock 317
逃避另一个%:
$stringWithVariables = 'About to deduct 50%% of %s %s from your Top-Up account.';
Run Code Online (Sandbox Code Playgroud)
小智 5
这很容易。
%在原来的前面放另一个%以逃避它。
例如,
$num=23;
printf("%%d of 23 = %d",$num);
Run Code Online (Sandbox Code Playgroud)
输出:
%d of 23 = 23
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
71745 次 |
| 最近记录: |