Example analysis of php file reading method
This article describes the php file reading method through examples. Share it with everyone for your reference. The details are as follows:
?
1
2
3
4
5
|
$file = fopen("Test//file.txt", "r"); //打开文件
echo fgetc($file); //读取文件中的一个字符
fclose($file); //关闭文件
?>
|
1
2
1
2
3
4
5
|
$file = fopen("Test//file.txt", "r"); //打开文件
echo fgets($file); //读取文件中的一行
fclose($file); //关闭文件
?>
|
3
1
2
3
4
5
|
$file = fopen("Test//file.txt", "r");
echo fread($file, 20); //读取文件中的前20个字符
fclose($file);
?>
|
4
5
1
2
3
4
5
6
7
|
$filename = "Test//file.txt";
$file = fopen($filename, "r");
$filesize = filesize($filename); //获取文件长度
echo fread($file, $filesize); //获取文件全部内容
fclose($file);
?>
|
|
$file = fopen("Test//file.txt", "r"); //Open the file
echo fgetc($file); //Read a character in the file
fclose($file); //Close the file
?>
|
?
1
2
3
45
|
<🎜>$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);<🎜>
<🎜>?>
|
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/1020288.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020288.htmlTechArticlePHP file reading method example analysis This article describes the php file reading method with an example. Share it with everyone for your reference. The details are as follows: ? 1 2 3 4 5 ?php $file = fopen(Test//file.txt, r); /...