演示:
---------------------------------------------------------------------------------------------
<?php
$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;
printf("%2$s %1$s", $strA, $strB); // 2$是指定参数位置
echo '<br />';
printf("填充: %'%10s", $str); //指定填充符为%字符串宽度为10
echo '<br />';
printf("二制制: %b", $num1);
echo '<br />';
printf("ASCII码: %c", $num2);
echo '<br />';
printf("整数: %d", $num3);
echo '<br />';
printf("浮点数: %.2f", $num4);
echo '<br />';
printf("八进制: %o", $num5);
echo '<br />';
printf("字符串: %s", $str);
echo '<br />';
printf("非小数: %u", $num6);
echo '<br />';
printf("十六进制: %x", $num7);
echo '<br />';
printf("十六进制: %X", $num8);
?>
---------------------------------------------------------------------------------------------
输出结果:
---------------------------------------------------------------------------------------------
B A
填充: %0758 jian
二制制: 101
ASCII码:
整数: 0
浮点数: 3.26
八进制: 10
字符串: 0758 jian
非小数: 1
十六进制: ffffff
十六进制: FFFFFF