PHP 实用函数sprintf()详解
2014-12-26 11:34
232 查看
1. 格式
sprintf(format, arg1, arg2, arg3,..) 把格式化的字符串写入到变量中,加粗字体为必需参数。
2. 说明
替换是逐步执行的,按参数顺序,但是如果%符号多于参数个数,则实用占位符(由数字和\$组成),例子:
echo $txt;
?>[/code]
输出:
%% - 返回百分比符号
%b - 二进制数
%c - 依照 ASCII 值的字符
%d - 带符号十进制数
%e - 可续计数法(比如 1.5e+3)
%u - 无符号十进制数
%f - 浮点数(local settings aware)
%F - 浮点数(not local settings aware)
%o - 八进制数
%s - 字符串
%x - 十六进制数(小写字母)
%X - 十六进制数(大写字母)
官方解释见:http://www.w3school.com.cn/php/func_string_sprintf.asp
sprintf(format, arg1, arg2, arg3,..) 把格式化的字符串写入到变量中,加粗字体为必需参数。
2. 说明
替换是逐步执行的,按参数顺序,但是如果%符号多于参数个数,则实用占位符(由数字和\$组成),例子:
<?php $number = 123; $txt = [code]sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number);
echo $txt;
?>[/code]
输出:
With 2 decimals: 123.00 With no decimals: 123 3. format参数中可用值:
%% - 返回百分比符号
%b - 二进制数
%c - 依照 ASCII 值的字符
%d - 带符号十进制数
%e - 可续计数法(比如 1.5e+3)
%u - 无符号十进制数
%f - 浮点数(local settings aware)
%F - 浮点数(not local settings aware)
%o - 八进制数
%s - 字符串
%x - 十六进制数(小写字母)
%X - 十六进制数(大写字母)
官方解释见:http://www.w3school.com.cn/php/func_string_sprintf.asp
相关文章推荐
- PHP echo,print,printf,sprintf函数之间的区别与用法详解
- php中sprintf()函数用法详解
- PHP之sprintf函数用法详解
- PHP echo,print,printf,sprintf函数之间的区别与用法详解
- PHP数字前补0的自带函数sprintf 和number_format的用法(详解)
- PHP之sprintf函数用法详解
- PHP sprintf()函数详解
- php sprintf 函数最新详解--转
- PHP strtotime函数详解
- [PHP]实用函数6第1/2页
- [PHP]实用函数5
- php header()函数使用详解
- php sprintf()函数让你的sql操作更安全
- php中错误函数error_reporting() 之详解
- 简单实用的分页函数(Php+mysql)
- PHP 之 函数 sprintf()
- php调用C代码的方法详解和zend_parse_parameters函数详解
- sprintf函数详解
- [PHP]实用函数7
- PHP中的sprintf()函数