ホームページ  >  記事  >  バックエンド開発  >  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) は 1 バイトを読み取ります。

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 までご連絡ください。