PHP - sprintf 函式



語法

string sprintf ( string $format [, mixed $args [, mixed $... ]] )

定義和用法

它用於格式化字串

返回值

它返回格式化的字串

引數

序號 引數及描述
1

format

它指定字串以及如何在其中格式化變數

2

arg1

它指定要插入到格式化字串中的第一個引數

3

arg2

它指定要插入到格式化字串中的第二個引數

示例

嘗試以下示例

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

結果應如下所示

123.000000
php_function_reference.htm
廣告