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 syntaxfwrite(file, string, length)
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.<?php $fn = fopen("myfile.txt","w"); $result = fwrite($fn,"Welcome to PHP!"); fclose($fn); ?>
Comments
Post a Comment