다음과 같은 출력을 원합니다.
보충 계정에서 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%
교환도 가능합니다.어떻게 탈출하지?
질문에 대한 답변
다른 사람과 함께 탈출하다%
:
$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
추가용%
당신의 언어 문자열에서, 당신은 단지 1이 아닌 2배의 퍼센트를 더하면 된다.
이것으로 충분합니다.
sprintf(
'%s (Cash Discount: %%%s, Deferred Discount: %%%s)',
$segment->name,
$segment->discount_cash,
$segment->discount_deferred, )
// Gold (Cash Discount: %25, Deferred Discount: %20)
이건 어때?
$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);
변수 배열에 백분율 기호만 추가하면 됩니다.