亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP fprintf() 函數(shù)

定義和用法

fprintf() 函數(shù)把格式化的字符串寫到指定的輸出流(例如:文件或數(shù)據(jù)庫)。

該函數(shù)返回被寫字符串的長度。

語法

fprintf(stream,format,arg1,arg2,arg++)
參數(shù) 描述
stream 可選。規(guī)定在哪里寫/輸出字符串。
format 必需。轉(zhuǎn)換格式。
arg1 必需。規(guī)定插到 format 字符串中第一個 % 符號處的參數(shù)。
arg2 可選。規(guī)定插到 format 字符串中第二個 % 符號處的參數(shù)。
arg++ 可選。規(guī)定插到 format 字符串中第三、四等等 % 符號處的參數(shù)。

說明

參數(shù) format 是轉(zhuǎn)換的格式,以百分比符號 ("%") 開始到轉(zhuǎn)換字符結(jié)束。下面的可能的 format 值:

  • %% - 返回百分比符號
  • %b - 二進(jìn)制數(shù)
  • %c - 依照 ASCII 值的字符
  • %d - 帶符號十進(jìn)制數(shù)
  • %e - 可續(xù)計數(shù)法(比如 1.5e+3)
  • %u - 無符號十進(jìn)制數(shù)
  • %f - 浮點數(shù)(local settings aware)
  • %F - 浮點數(shù)(not local settings aware)
  • %o - 八進(jìn)制數(shù)
  • %s - 字符串
  • %x - 十六進(jìn)制數(shù)(小寫字母)
  • %X - 十六進(jìn)制數(shù)(大寫字母)

arg1, arg2, ++ 等參數(shù)將插入到主字符串中的百分號 (%) 符號處。該函數(shù)是逐步執(zhí)行的。在第一個 % 符號中,插入 arg1,在第二個 % 符號處,插入 arg2,依此類推。

提示和注釋

注釋:如果 % 符號多于 arg 參數(shù),則您必須使用占位符。占位符被插入 % 符號之后,由數(shù)字和 "\$" 組成。請參見例子 3。

提示: 相關(guān)函數(shù): printf()sprintf()、 vfprintf()、 vprintf() 以及 vsprintf()

例子

例子 1

<?php
$str = "Hello";
$number = 123;
$file = fopen("test.txt","w");
echo fprintf($file,"%s world. Day number %u",$str,$number);
?>

輸出:

27

以下文本將寫入 "test.txt":

Hello world. Day number 123

例子 2

<?php
$number = 123;
$file = fopen("test.txt","w");
fprintf($file,"%f",$number);
?>

輸出:

123.000000

例子 3

使用占位符:

<?php
$number = 123;
$file = fopen("test.txt","w");
fprintf($file,"With 2 decimals: %1\$.2f\nWith no decimals: %1\$u",$number);
?>

以下文本將寫入 "test.txt":

With 2 decimals: 123.00
With no decimals: 123