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