PHP fwrite

PHP fwrite() 函式寫入檔案(可安全用於二進制檔案)。

基本介紹

  • 中文名:PHP fwrite
  • 語法:fwrite(file,string,length
  • file:必需。規定要寫入的打開檔案
  • string:必需。規定要寫入檔案的字元串
語法,說明,例子,實例,

語法

fwrite(file,string,length)
參數
描述
file
必需。規定要寫入的打開檔案。
string
必需。規定要寫入檔案的字元串。
length
可選。規定要寫入的最大位元組數。

說明

fwrite() 把 string 的內容寫入檔案指針 file 處。 如果指定了 length,當寫入了 length 個位元組或者寫完了 string 以後,寫入就會停止,視乎先碰到哪種情況。
fwrite() 返回寫入的字元數,出現錯誤時則返回 false。

例子

<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
輸出:
21

實例

向檔案中寫入字元
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Boppern";
fwrite($fh, $stringData);
$stringData = "Tracy Tannern";
fwrite($fh, $stringData);
fclose($fh);
PHP Filesystem 函式

相關詞條

熱門詞條

聯絡我們