在PHP中,經(jīng)常會遇見%s與%d,本篇將介紹%s與%d是什么意思?
PHP sprintf() 函數(shù)用到的參數(shù)
printf — 輸出格式化字符串
sprintf() 函數(shù)把格式化的字符串寫入一個變量中。
%% - 返回百分比符號
%b - 二進制數(shù)
%c - 依照 ASCII 值的字符
%d - 帶符號十進制數(shù)
%e - 可續(xù)計數(shù)法(比如 1.5e+3)
%u - 無符號十進制數(shù)
%f - 浮點數(shù)(local settings aware)
%F - 浮點數(shù)(not local settings aware)
%o - 八進制數(shù)
%s - 字符串
%x - 十六進制數(shù)(小寫字母)
%X - 十六進制數(shù)(大寫字母)
示例代碼如下:
<?php
$colors = ['red','green','blue'];
printf('<pre>%s</pre>',print_r($colors,true));
printf(print_r($colors,true));
?>
輸出效果如下:
微信掃碼
關(guān)注PHP中文網(wǎng)服務號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號