PHP fputs()Function


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual

Definition and Usage

The fputs() function writes content to an opened file.

The function stops running when it reaches the specified length or reads to the end of file (EOF), whichever comes first.

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

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

Syntax

fputs(file,string,length)

Parameters Description
file Required. Specifies the open file to write to.
string Required. Specifies the string to write to the open file.
length Optional. Specifies the maximum number of bytes to write.


Tips and Notes

Tip:This function is binary-safe. (Meaning binary data (such as images) and character data can both be written using this function.)


Example

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

The above code will output:

21


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual Other Extensions