sprintf();//把百分号(%)符号替换成一个作为参数进行传递的变量
<?php
$number = 2;
$str = "Shanghai";
$txt = sprintf("There are %u million cars in %s.",$number,$str);
echo $txt;
?>
//There are 2 million cars in Shanghai.
使用格式值 %f:
<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
使用占位符:
<?php $number = 123;
$txt = sprintf("带两位小数:%1\$.2f <br>
不带小数:%1\$u",$number);
echo $txt; ?>
//123.00 123