Home >Backend Development >PHP Tutorial >Example analysis of php file reading method_PHP tutorial
This article describes the php file reading method through examples. Share it with everyone for your reference. The details are as follows:
?
2
3
5
|
$file = fopen("Test//file.txt", "r"); //Open the file
|
1
2
3
4 |
<🎜>$file = fopen("Test//file.txt", "r"); //Open the file<🎜> <🎜>echo fgets($file); //Read a line in the file<🎜> <🎜>fclose($file); //Close the file<🎜> <🎜>?> |
1 2 3 4 5 | <🎜>$file = fopen("Test//file.txt", "r");<🎜> <🎜>echo fread($file, 20); //Read the first 20 characters in the file<🎜> <🎜>fclose($file);<🎜> <🎜>?> |
1 2 3 4 5 6 7 | <🎜>$filename = "Test//file.txt";<🎜> <🎜>$file = fopen($filename, "r");<🎜> <🎜>$filesize = filesize($filename); //Get the file length<🎜> <🎜>echo fread($file, $filesize); //Get the entire content of the file<🎜> <🎜>fclose($file);<🎜> <🎜>?> |