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//from   w  w w .  ja va  2 s. c  o m
$file = fopen("test.txt","w");
echo fputs($file,"Hello World from java2s.com!");
fclose($file);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions