English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A função printf() é usada para output de strings formatadas.
int printf ( string $format [, mixed $args [, mixed $... ]])
ele retorna a string formatada de saída
ele retorna o comprimento da string de saída.
número | parâmetros e descrições |
---|---|
1 | format especificar uma string e como formatar as variáveis dentro dela.valores de formatação possíveis:
valores de formatação adicionais. É necessário coloca-los entre % e a letra (por exemplo %.2f):
Note:If multiple format values are used, they must be used in the order specified above and cannot be disordered. |
2 | arg1 Required. Specify the parameter to be inserted into the format string at the first % symbol. |
3 | arg2 Optional. Specify the parameter to be inserted into the format string at the second % symbol. |
4 | arg ... Optional. Specify the parameter to be inserted into the format string at the third, fourth, etc. % symbols. |
Try the following example, output formatted data and string:
<?php ////Output formatted string printf("pt.oldtoolbag.com simply easy learning\n"); //Use the format value %f to format the number: $number = 2123; printf("%f",$number); $str = "0758 jian"; $strA = "A"; $strB = "B"; $num1 = 5; $num2 = 5; $num3 = 0.25; $num4 = 3.2567; $num5 = 8; $num6 = 1.735; $num7 = 16777215; $num8 = 16777215; echo '<br />'; printf("%s %s", $strA, $strB); echo '<br />'; printf("Padding: %'%10s", $str); //Specify the padding character as%string width as10 echo '<br />'; printf("Binary: %b", $num1); echo '<br />'; printf("ASCII code: %c", $num2); echo '<br />'; printf("Integer: %d", $num3); echo '<br />'; printf("Floating-point: %.2f", $num4); echo '<br />'; printf("Octal: %o", $num5); echo '<br />'; printf("String: %s", $str); echo '<br />'; printf("Non-decimal: 眻, $num6); echo '<br />'; printf("Hexadecimal: %x", $num7); echo '<br />'; printf("Hexadecimal: %X", $num8); ?>Test and see‹/›
Output result
pt.oldtoolbag.com simply easy learning 2123.000000A2 B1 Padding: %0758 jian Binary: 101 ASCII code: Integer: 0 Floating-point: 3.26 Octal: 10 String: 0758 jian Non-decimal: 1 Hexadecimal: ffffff Hexadecimal: FFFFFF