//生成4位数,不足前面补0$var=sprintf("%04d", 2);echo $var;//结果为0002echo date('y_m_d', time()).'_'.sprintf('d', rand(0,99));?>复制代码sprintf()函数有没有感觉很像c语言1,语法sprintf(format,arg1,arg2,arg++)参数 描述format 必需。转换格式。
arg1 必需。规定插到 format 字符串中第一个 % 符号处的参数。
arg2 可选。规定插到 format 字符串中第二个 % 符号处的参数。
arg++ 可选。规定插到 format 字符串中第三、四等等 % 符号处的参数。2,说明 (bbs.it-home.org 脚本学堂 编辑整理)$number = 123;$txt = sprintf("%f",$number);echo $txt;?>复制代码3,格式数字 number_format()$number = 1234.56;// english notation (default)$english_format_number = number_format($number);// 1,235// french notation$nombre_format_francais = number_format($number, 2, ',', ' ');// 1 234,56$number = 1234.5678;// english notation without thousands seperator$english_format_number = number_format($number, 2, '.', '');// 1234.57?>立即学习“PHP免费学习笔记(深入)”;复制代码
