PHP fputs() Function

Definition and Usage

The fputs() function writes to a file (can be safely used for binary files).

The fputs() function is fwrite() Alias of the function.

Syntax

fputs(file,string,length)
Parameters Description
file Required. Specifies the file to write to.
string Required. Specifies the string to write to the file.
length Optional. Specifies the maximum number of bytes to write.

Description

fwrite() writes string the content is written to the file pointer file . If specified lengthwhen written length bytes or when finished writing string From then on, writing will stop, depending on which condition is met first.

fwrite() returns the number of characters written, or false if an error occurs.

Example

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

Output:

21