PHP格式化输出printf,sprintf,vprintf,fprintf
2011-04-30 19:49
567 查看
语法:
format格式:
%% - Returns a percent sign
%% -返回百分号
%b - Binary number
%b –返回二进制数
%c - The character according to the ASCII value
%c –返回与ASCII值相对应的字符
%d - Signed decimal number
%d –带有正负号的十进制数
%e - Scientific notation (e.g. 1.2e+2)
%e –科学计数符号(如:1.2e+2)
%u - Unsigned decimal number
%u –不带正负号的十进制数
%f - Floating-point number (local settings aware)
%f – 浮点数据(本地设置)
%F - Floating-point number (not local settings aware)
%F –浮点数据(非本地设置)
%o - Octal number
%o –十进制数
%s - String
%s –字符串
%x - Hexadecimal number (lowercase letters)
%x –十六进制数(小写字母)
%X - Hexadecimal number (uppercase letters)
%X –十六进制数(大写字母)
Additional format values. These are placed between the % and the letter (example %.2f):
其它格式的值。它是位于%和字母之间的(如:%.2f)
n$ (Specifies the argment to use. The n, which type of integer, is the order of argments.The first argment is 1.)
指定使用的参数,n为整数,为format后参数的序号,从1开始编号。
+ (Forces both + and - in front of numbers. By default, only negative numbers are marked)
+(在数字前加上+和-;默认情况下,只有负数是被标记出来的)
'
(Specifies what to use as padding. Default is space. Must be used
together with the width specifier. Example: %'x20s (this uses "x" as
padding)
’(指定使用什么作为补白,默认值是空格。它必须与宽度指定器一起使用。如:%'x20s(使用“x”作为padding))
当填充字符为"0"时,可以不加这个单引号,如:%04d,表示,固定4位宽度,不够使用0填充。
- (Left-justifies the variable value)
- (左调整变量值)
[0-9] (Specifies the minimum width held of to the variable value)
[0-9](指定变量值的最小宽度)
.[0-9] (Specifies the number of decimal digits or maximum string length)
.[0-9](指定十进制数值或最大字符串长度)
Note:
If multiple additional format values are used, they must be in the same order as above.
注意:如果使用附加格式值,那么它必须与上述顺序相同
int printf ( string $format [, mixed $args [, mixed $... ]] ) string sprintf ( string $format [, mixed $args [, mixed $... ]] ) int vprintf ( string $format , array $args ) int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] )
format格式:
%% - Returns a percent sign
%% -返回百分号
%b - Binary number
%b –返回二进制数
%c - The character according to the ASCII value
%c –返回与ASCII值相对应的字符
%d - Signed decimal number
%d –带有正负号的十进制数
%e - Scientific notation (e.g. 1.2e+2)
%e –科学计数符号(如:1.2e+2)
%u - Unsigned decimal number
%u –不带正负号的十进制数
%f - Floating-point number (local settings aware)
%f – 浮点数据(本地设置)
%F - Floating-point number (not local settings aware)
%F –浮点数据(非本地设置)
%o - Octal number
%o –十进制数
%s - String
%s –字符串
%x - Hexadecimal number (lowercase letters)
%x –十六进制数(小写字母)
%X - Hexadecimal number (uppercase letters)
%X –十六进制数(大写字母)
Additional format values. These are placed between the % and the letter (example %.2f):
其它格式的值。它是位于%和字母之间的(如:%.2f)
n$ (Specifies the argment to use. The n, which type of integer, is the order of argments.The first argment is 1.)
指定使用的参数,n为整数,为format后参数的序号,从1开始编号。
+ (Forces both + and - in front of numbers. By default, only negative numbers are marked)
+(在数字前加上+和-;默认情况下,只有负数是被标记出来的)
'
(Specifies what to use as padding. Default is space. Must be used
together with the width specifier. Example: %'x20s (this uses "x" as
padding)
’(指定使用什么作为补白,默认值是空格。它必须与宽度指定器一起使用。如:%'x20s(使用“x”作为padding))
当填充字符为"0"时,可以不加这个单引号,如:%04d,表示,固定4位宽度,不够使用0填充。
- (Left-justifies the variable value)
- (左调整变量值)
[0-9] (Specifies the minimum width held of to the variable value)
[0-9](指定变量值的最小宽度)
.[0-9] (Specifies the number of decimal digits or maximum string length)
.[0-9](指定十进制数值或最大字符串长度)
Note:
If multiple additional format values are used, they must be in the same order as above.
注意:如果使用附加格式值,那么它必须与上述顺序相同
相关文章推荐
- 各种输出函数的比较(printf/fprintf/sprintf/snprintf/vprintf/vfprintf/vsprintf/vsnprintf)
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换函数
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换函数
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换
- php中格式化输出函数vprintf printf sprintf sscanf
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- php中格式化输出函数vprintf printf sprintf sscanf
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换
- C语言--格式化输入/输出函数(printf/scanf,fprintf/fscanf,sprintf,sscanf)
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换函数
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- PHP字符串函数之 sscanf echo print sprintf vsprintf printf vprintf fprintf vfprintf
- F# Interactive技巧:在sprintf/printf/fprintf中使用AddPrinter,addPrintTransformer和%A来格式化数据
- php输出echo、print、print_r、printf、sprintf、var_dump的区别比较
- F# Interactive技巧:在sprintf/printf/fprintf中使用AddPrinter,addPrintTransformer和%A来格式化数据