PHP sprintf()函数用例解析
<div class="codetitle"><a style="CURSOR: pointer" data="11675" class="copybut" id="copybut11675" onclick="doCopy('code11675')"> 代码如下:<div class="codebody" id="code11675">
说明参数 format 是转换的格式,以百分比符号 ("%") 开始到转换字符结束。下面的可能的 format 值:
arg1,++ 等参数将插入到主字符串中的百分号 (%) 符号处。该函数是逐步执行的。在第一个 % 符号中,插入 arg1,在第二个 % 符号处,插入 arg2,依此类推。 代码如下: $str = "Hello"; $number = 123; $txt = sprintf("%s world. Day number %u",$str,$number); echo $txt; ?> 输出: Hello world. Day number 123 例子 2 代码如下: $number = 123; $txt = sprintf("%f",$number); echo $txt; ?> 输出: 123.000000 例子 3 代码如下: $number = 123; $txt = sprintf("With 2 decimals: %1$.2f With no decimals: %1$u",$number); echo $txt; ?> 输出: With 2 decimals: 123.00 With no decimals: 123 更详细的可以参考 //www.52php.cn/w3school/php/func_string_sprintf.htm (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |