时间:2021-07-01 10:21:17 帮助过:15人阅读
演示:
---------------------------------------------------------------------------------------------
$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 '
';
printf("填充: %'%10s", $str); //指定填充符为%字符串宽度为10
echo '
';
printf("二制制: %b", $num1);
echo '
';
printf("ASCII码: %c", $num2);
echo '
';
printf("整数: %d", $num3);
echo '
';
printf("浮点数: %.2f", $num4);
echo '
';
printf("八进制: %o", $num5);
echo '
';
printf("字符串: %s", $str);
echo '
';
printf("非小数: %u", $num6);
echo '
';
printf("十六进制: %x", $num7);
echo '
';
printf("十六进制: %X", $num8);
?>
---------------------------------------------------------------------------------------------
输出结果:
---------------------------------------------------------------------------------------------
B A
填充: %0758 jian
二制制: 101
ASCII码:
整数: 0
浮点数: 3.26
八进制: 10
字符串: 0758 jian
非小数: 1
十六进制: ffffff
十六进制: FFFFFF
http://www.bkjia.com/PHPjc/364176.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364176.htmlTechArticleprintf()函数优点在于可以格式化输出! 格式如下:%['padding_character][-][width][.precision]type 所有的转换说明都是以%开始,如果想打印一个%符号,必须...