最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP sprintf() 函數(shù)的應(yīng)用(定義和用法)

 更新時(shí)間:2012年06月29日 12:07:54   作者:  
sprintf定義和用法,sprintf() 函數(shù)用于把格式化的字符串寫入一個(gè)變量中。

語(yǔ)法

sprintf(format,arg1,arg2,arg++)
參數(shù) 描述
format 必需。轉(zhuǎn)換格式。
arg1 必需。規(guī)定插到 format 字符串中第一個(gè) % 符號(hào)處的參數(shù)。
arg2 可選。規(guī)定插到 format 字符串中第二個(gè) % 符號(hào)處的參數(shù)。
arg++ 可選。規(guī)定插到 format 字符串中第三、四等等 % 符號(hào)處的參數(shù)。

說(shuō)明

參數(shù) format 是轉(zhuǎn)換的格式,以百分比符號(hào) ("%") 開始到轉(zhuǎn)換字符結(jié)束。下面的可能的 format 值:
%% - 返回百分比符號(hào)
%b - 二進(jìn)制數(shù)
%c - 依照 ASCII 值的字符
%d - 帶符號(hào)十進(jìn)制數(shù)
%e - 可續(xù)計(jì)數(shù)法(比如 1.5e+3)
%u - 無(wú)符號(hào)十進(jìn)制數(shù)
%f - 浮點(diǎn)數(shù)(local settings aware)
%F - 浮點(diǎn)數(shù)(not local settings aware)
%o - 八進(jìn)制數(shù)
%s - 字符串
%x - 十六進(jìn)制數(shù)(小寫字母)
%X - 十六進(jìn)制數(shù)(大寫字母)
arg1, arg2, ++ 等參數(shù)將插入到主字符串中的百分號(hào) (%) 符號(hào)處。該函數(shù)是逐步執(zhí)行的。在第一個(gè) % 符號(hào)中,插入 arg1,在第二個(gè) % 符號(hào)處,插入 arg2,依此類推

提示和注釋
注釋:如果 % 符號(hào)多于 arg 參數(shù),則您必須使用占位符。占位符插到 % 符號(hào)后面,由數(shù)字和 "\$" 組成。請(qǐng)參見例子 3。

例子
例子 1

復(fù)制代碼 代碼如下:

?
<?php
$str = "Hello";
$number = 123;
$txt = sprintf("%s world. Day number %u",$str,$number);
echo $txt;
?>

輸出:

Hello world. Day number 123

例子 2
復(fù)制代碼 代碼如下:

<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
 

輸出:

123.000000

例子 3
復(fù)制代碼 代碼如下:

<?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number);
echo $txt;
?>

輸出:
復(fù)制代碼 代碼如下:

With 2 decimals: 123.00
With no decimals: 123

例子4
復(fù)制代碼 代碼如下:

<?php
$ctype_primary = strtolower('application');
$ctype_secondary = strtolower('pdf');
$mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
echo $mimetype;
?>

輸出:
復(fù)制代碼 代碼如下:

application/pdf

相關(guān)文章

最新評(píng)論

乐至县| 山东| 集安市| 瑞安市| 延川县| 和静县| 贵南县| 天镇县| 承德市| 密云县| 兴义市| 秭归县| 吉水县| 东台市| 铁岭县| 萨迦县| 新郑市| 渝中区| 孝感市| 敖汉旗| 桂林市| 安国市| 宜都市| 定日县| 肇东市| 西和县| 广水市| 博客| 全椒县| 庄浪县| 五寨县| 卢氏县| 库车县| 油尖旺区| 荣成市| 河源市| 壤塘县| 东莞市| 济南市| 清丰县| 南平市|