1. File specifies filename to write 2. String specifies the string to write to file 3. Lenght specifies maximum number of bytes to write to file (optional)

Syntax

PHP fwrite() function uses following syntax

Example

Below is the sample example of writing data to file using php script. In below example first line will open myfile.txt in edit mode in current directory. Second line will write string to file, you can also specify the lenght here and result the number of bytes written. In case of failure, FALSE will be returned. Third line will close open file.

Output:

This function returns total number of bytes written to a file or returns FALSE in case of failure.