PHP Tutorial - PHP fputs() Function






Definition

The fputs() writes to an open file.

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

Syntax

PHP fputs() Function has the following syntax.

fputs(file,string,length)

Parameter

Parameter Is RequiredDescription
fileRequired.Open file to write to
stringRequired.String to write to the open file
lengthOptional.Maximum number of bytes to write

Return

This function returns the number of bytes written on success, or FALSE on failure.





Example


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

The code above generates the following result.