php, read file, write file, how to read file, how to write file, read entire file, file append php: read, write file
(Website Helper) php: read, write file Number of Visitors: Site Map

php: how to read file, write file, append file?



Website Design
Website Promotion
Graphic Design
Programming
Free Software
Computer Tips
Discount Stores
This site provides users with the information about php, read file, write file, how to read file, how to write file, read entire file, file append, and more.

If you think that this site is helpful, please recommend your friends to visit our site.



How to read file, write file, and append file in php?

The following is the code to read file, write file, and append file in php:

1. How to write file in php?


< ?php $file = "test.txt"; $f_handle = fopen($myFile, 'w') or die("can't open file"); $inputData = "this is a test\n"; fwrite(f_handle, $inputData); fclose(f_handle); ? >
Note:

'w' is for writing or replacing the entire contents of the file. For append, use 'a'.

2. How to read file in php?


< ?php $file = "test.txt"; $f_handle = fopen($file, "r"); while (!feof($f_handle)) { $line = fgets($f_handle); echo $line; } fclose($f_handle); ? >
An example of reading entire file:


< ?php $file = "test.txt"; $entire_file = file_get_contents($file); echo $entire_file; ? >
(Website Helper) php: read, write file (c) EduSoftMax - www.edusoftmax.com