반응형
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%교환도 가능합니다.어떻게 탈출하지?
다른 사람과 함께 탈출하다%:
$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);
변수 배열에 백분율 기호만 추가하면 됩니다.
언급URL : https://stackoverflow.com/questions/3666734/php-sprintf-escaping
반응형
'source' 카테고리의 다른 글
| MySQL 문자열에서 n번째 단어와 단어 발생 횟수를 추출하는 방법은 무엇입니까? (0) | 2023.02.01 |
|---|---|
| 데이터베이스 가져오기 오류 구문 (0) | 2023.02.01 |
| set Timeout(fn, 0)이 유용한 이유는 무엇입니까? (0) | 2023.02.01 |
| 범례를 줄거리 외부에 배치하는 방법 (0) | 2023.02.01 |
| PHP에서 HTTP 메서드 알아보기 (0) | 2023.02.01 |