Php implements the method of opening files in read-only mode. Php: how to open a file in read-only mode this article mainly introduces php's method of opening a file in read-only mode. The example analyzes the function and usage skills of fopen function in php, how to open a file in read-only mode using php
This article describes how to open a file in read-only mode in php. The example analyzes the function and usage skills of the fopen function in php. For more information, see
This example describes how to open a file in read-only mode in php. Share it with you for your reference. The specific analysis is as follows:
In php, you can open a file through fopen (). The second parameter is set to "r", indicating that the file is opened in read-only mode. the function returns a file handle, other functions can use this file handle to read files in different ways.
?
1 2 3 4 5 6 |
$ File = fopen ("/tmp/file.txt", "r "); Print ("Type of file handle:". gettype ($ file). "\ n "); Print ("The first line from the file handle:". fgets ($ file )); Fclose ($ file ); ?> |
The above code returns the following results:
Type of file handle: resource
The first line from the file handle: Welcome to sharejs.com php tutorials
After the file is read, use the fclose () function to close the file handle to release the resource.
I hope this article will help you with php programming.
This article describes how to open a file in read-only mode in php. The example analyzes the function and usage skills of fopen function in php...