ホームページ  >  記事  >  バックエンド開発  >  PHP 五 入门 读、写文本文件(二)

PHP 五 入门 读、写文本文件(二)

WBOY
WBOYオリジナル
2016-06-13 11:00:18751ブラウズ

PHP 5 入门 读、写文本文件(二)

??

===============

写文件

===============

$realFiePath = "D:/test.txt";

$fileContent = "Test 2011 03 12.";

?

$file = fopen($realFiePath, 'wb');

fwrite($file, $fileContent );

fclose($file);

?

?

===============

读文件

===============

$realFiePath = "D:/test.txt";

$size = intval(sprintf("%u", filesize($realFiePath)));
$handle = fopen($realFiePath, "rb");
$fileContent = "";
??while (!feof($handle)) {
????? $fileContent .= fread($handle, $size);
????? ob_flush();
??? ??flush();
??}
??fclose($handle);

?

echo $fileContent ;

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。