Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

fwrite()

Example

Compose anything to a file that is open:

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

The following is the result of the code above:

21

Definition and Usage

To an open file, the fwrite() writes.
When the function reaches the designated length or the end of the file (EOF), whichever comes first, it will terminate.

Syntax

fwrite(filestringlength)

Parameter Values

 

Parameter

Description

file

Essential. The open file to write to is specified.

string

Essential. gives the string that should be written to the open file.

length

Not required. indicates the most bytes that can be written.

Technical Details

Return Value:

The amount of bytes written; if an error occurs, FALSE

PHP Version:

4.0+

Binary Safe:

Yes