fputs (file, string, length)Parameters used:
Function fputs() in PHP takes three parameters.
Returns the number of bytes written on success, or False on error.Exceptions
Input: $myfile = fopen ("gfg.txt", "w"); echo fputs ($myfile, "Geeksforengineer is a portal of engineer!"); fclose ($myfile); Output: 35 Input: $myfile = fopen ("gfg.txt", "w"); echo fputs ($myfile, "Geeksforengineer is a portal of engineer!", 13); fclose ($myfile); fopen ("gfg.txt", "r"); echo fread ($myfile, filesize ("gfg.txt")); fclose ($myfile); Output: GeeksforengineerThe programs below illustrate the fputs() function:Program 1
// Open file
$myfile
=
fopen
(
"gfg .txt "
,
" w "
);
// write content to file using fputs
echo
fputs
(
$myfile
,
" Geeksforengineer is a portal of engineer! "
);
// close the file
fclose (
$myfile
);
?>
Output:35
Program 2 // Open file
$myfile
=
fopen
(
"gfg.txt"
,
" w "
);
// write content to file with specified line length using fputs
echo
fputs
(
$myfile
,
"Geeksforengineer is a portal of engineer!"
, 13);
// close the file
fclose (
$myfile
);
// open the same file to read its contents
fopen
(
"gfg.txt"
,
"r"
);
echo
fread
(
$myfile
,
(
"gfg.txt"
));
// close the file
fclose (
$myfile
);
?>
Output:Geeksforengineer
Link:
http: / /php.net/manual/en/function.fputs.php