PHP5入门之读写文本文件
发布时间:2018-05-25 编辑:jiaochengji.com
本文介绍了php5入门之读写文本文件的例子,比较简单,有关php中fopen、fread与fwrite函数的用法,有需要的朋友参考下。
例子,php读写文本文件。
复制代码 代码示例:
===============
写文件
===============
$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 ;
写文件
===============
$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 ;
您可能感兴趣的文章:
PHP5入门之读写文本文件
php文件怎么打开?php文件是什么文件?
php5是什么
PHP文档工具
php5中加载类(autoload)的实现方法
解决phpMyAdmin Cannot start session without errors错误
python写文件怎么读出来
Python3爬虫进阶:TXT文本存储
js读写文件实例代码(读取与写入文本文件)
php入门教程(索引)
上一篇:php快递单号查询接口实例
下一篇:PHP如何生成自适应大小的缩略图
[关闭]