Home >Backend Development >PHP Tutorial >Example analysis of php file reading method, _PHP tutorial
This article describes the php file reading method in an example. Share it with everyone for your reference. The details are as follows:
<?php $file = fopen("Test//file.txt", "r"); //打开文件 echo fgetc($file); //读取文件中的一个字符 fclose($file); //关闭文件 ?>
<?php $file = fopen("Test//file.txt", "r"); //打开文件 echo fgets($file); //读取文件中的一行 fclose($file); //关闭文件 ?>
<?php $file = fopen("Test//file.txt", "r"); echo fread($file, 20); //读取文件中的前20个字符 fclose($file); ?>
<?php $filename = "Test//file.txt"; $file = fopen($filename, "r"); $filesize = filesize($filename); //获取文件长度 echo fread($file, $filesize); //获取文件全部内容 fclose($file); ?>
I hope this article will be helpful to everyone’s PHP programming design.