Home  >  Article  >  Backend Development  >  PHP 五 入门 读、写文本文件(二)

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

WBOY
WBOYOriginal
2016-06-13 13:02:41975browse

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 ;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn