php读取文件的各种方法

时间:2023-03-08 23:03:26
php读取文件的各种方法

博客根据http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles个人总结

获取文件全部内容

以下归类是按平时我们通常的使用方法总结

一次性获取

file_get_contents($path),将整个文件内容写入到一个字符串中

分段获取

$headle = fopen();

fgets($headle,$length);

fread($headle,$length);

feof($headle);//判断文件结尾

截取文件部分内容

file_get_contents($path,$include_path,null,$start,$max_length);
fseek移动指针方法
$headle = fopen();
fseek($headle,$start);//将指针移动到$start位置
fread($headle,$length);