來源:https://blog.csdn.net/zxh1220/article/details/79709207
HP 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; ?>
就是把%s替換為$str,把%d替換為$number
輸出:
Hello world. number 123