Home >Backend Development >PHP Tutorial >Example analysis of php file reading method_PHP tutorial

Example analysis of php file reading method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:49:11853browse

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 filefclose($file); //Close the file ?>
 ?
1 2 3 4
5
<🎜>$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); /...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn