首页  >  文章  >  后端开发  >  php读资料的4中方法

php读资料的4中方法

WBOY
WBOY原创
2016-06-13 13:25:12775浏览

php读文件的4中方法。
fopen

$fp = fopen("download.php","rb");
	while(!feof($fp)){
		echo "fopen: ".fgets($fp);
	}
	fclose($fp);



说明:
对于fgets($handle,$length);
fgets是读取一行,返回$length-1长度的数据。
fgetc($handle)是读一个字节。

file
$lines = file("download.php");
	foreach($lines as $line){
		echo "file: ".$line;
	}

file_get_contents
$content = file_get_contents("download.php");
echo "get_contents: ".$content;

readfile 据说readfile是不占php线程本身内存的。
echo "readfile: ";
	readfile("download.php");
	flush();

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn