In this article, you will learn how to write in file in PHP. The fwrite() function in PHP writes to an open file.
what is the syntax of the FWRITE function in php?
fwrite(file, string, length)
Parameter | Description |
---|---|
file | Required. Specifies the open file to write to |
string | Required. Specifies the string to write to the open file |
length | Optional. Specifies the maximum number of bytes to write |
examples of the FWRITE function
Example 1. In this example, we write to an open file.
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>