您的位置 首页 php

在PHP中 sprintf() 函数常用到的参数%s与%d分别是什么意思?

PHP sprintf() 函数用到的参数

printf — 输出格式化 字符串

sprintf() 函数把格式化的字符串写入一个变量中。

%% – 返回百分比符号

%b – 二进制数

%c – 依照 ASCII 值的字符

%d – 带符号十进制数

%e – 可续计数法(比如 1.5e+3)

%u – 无符号十进制数

%f – 浮点数 (local settings aware)

%F – 浮点数(not local settings aware)

%o – 八进制数

%s – 字符串

%x – 十六进制数(小写字母)

%X – 十六进制数(大写字母)

<?php

$str = “Hello”;

$number = 123;

$txt = sprintf(“%s world. number %d”,$str,$number);

echo $txt;

?>

输出:

Hello world. number 123

文章来源:智云一二三科技

文章标题:在PHP中 sprintf() 函数常用到的参数%s与%d分别是什么意思?

文章地址:https://www.zhihuclub.com/149936.shtml

关于作者: 智云科技

热门文章

网站地图