PHP fputs() 函數
定義和用法
fputs() 函數寫入文件(可安全用于二進制文件)。
fputs() 函數是 fwrite() 函數的別名。
語法
fputs(file,string,length)
參數 | 描述 |
---|---|
file | 必需。規定要寫入的打開文件。 |
string | 必需。規定要寫入文件的字符串。 |
length | 可選。規定要寫入的最大字節數。 |
說明
fwrite() 把 string 的內容寫入文件指針 file 處。 如果指定了 length,當寫入了 length 個字節或者寫完了 string 以后,寫入就會停止,視乎先碰到哪種情況。
fwrite() 返回寫入的字符數,出現錯誤時則返回 false。
實例
<?php $file = fopen("test.txt","w"); echo fputs($file,"Hello World. Testing!"); fclose($file); ?>
輸出:
21