Latest web development tutorials

PHP fputs () function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual

Definition and Usage

fputs () function writes to an open file.

Function at specified length or read the end of the file (EOF) (whichever comes first), stop running.

If the function is executed successfully, it returns the number of bytes written. If it fails, it returns FALSE.

fputs () function is the fwrite () function is an alias.

grammar

fputs(file,string,length)

参数 描述
file 必需。规定要写入的打开文件。
string 必需。规定要写入打开文件的字符串。
length 可选。规定要写入的最大字节数。


Tips and Notes

Tip: This function is binary safe.(Meaning that the binary data (such as images) and character data can use this function to write.)


Examples

<?php
$file = fopen("test.txt","w");
echo fputs($file,"Hello World. Testing!");
fclose($file);
?>

The code above will output:

21


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual