This article mainly introduces the PHP implementation to open the file in a read-only way, example analysis of PHP fopen function and the use of skills, the need for friends can refer to the
The example in this article describes how PHP implements a read-only open file. Share to everyone for your reference. The specific analysis is as follows:
PHP can open a file by fopen (), the second parameter is set to "R" means read-only open, function returns a file handle, other functions can use this file handle for different ways to read the file
?
| 1 2 3 4 5 6 |
<?php $file = fopen ("/tmp/file.txt", "R"); Print ("Type of File Handle:".) GetType ($file). "N"); Print ("The" the "the" the "the" File Handle: ".) Fgets ($file)); Fclose ($file);?> |
The code above returns the following results
Type of File Handle:resource
The Handle:welcome to sharejs.com PHP tutorials
After the file read is complete, you need to use the fclose () function to close the file handle to free up resources
I hope this article will help you with your PHP program design.