一尘不染

PHP sprintf转义%

php

我想要以下输出:

将从您的充值帐户中扣除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 ...因为它也考虑使用%in 50%进行替换。我该如何逃脱?


阅读 458

收藏
2020-05-29

共1个答案

一尘不染

与另一个转义%

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