echo ( "Nội dung của file:
" ); echo ( "
$ filetext
" ); ?>
Save the program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php to see the result.
A new file can be written or text can be appended to an existing file using the fwrite () function in PHP. This function requires two parameters: the file pointer and the data string to be written. An optional 3rd integer parameter can be added to determine the length of the data to be written. If the third parameter is added, recording will stop after the specified length has been reached.
The following example creates a new text file, and writes a short text to its head. After closing this file, the existence of this file is confirmed by the file_exist () function, which will receive the file name as a parameter.
Write files in PHP
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
And now the content of tmp.txt will be:
We will discuss all functions related to input and output files in the File Processing Function chapter in PHP .
Follow tutorialspoint
Previous article: Insert file in PHP
Next lesson: PHP function