file 读取方式

<?php

//文件变量
$file_path="test.txt";

if(file_exists($file_path)){
//打开文件
$fp=fopen($file_path,"a+");
//读内容,输入 *****第一种读取方式
$conn=fread($fp, filesize($file_path));
//echo "文件的内容是".$conn."<br/>";
//在默认情况下,得到的内容不会换行
//不认\r\n是换行符,只认<br/>
$conn=str_replace("\r\n","<br/>",$conn);
echo $conn;
}else{
echo "文件不存在";
}
// fclose($fp);

//*********第二种读取方式********

$con=file_get_contents($file_path);
$con=str_replace("\r\n","<br/>",$conn);
echo $con;


//********第三种读取方式 循环读取(对付大文件)
if(file_exists($file_path)){

$fp=fopen($file_path,"a+");

//设置一次读取多少个字节
$buffer=1024;
$str="";
//一边读,一边判断是否达到达文件的末尾
while (!feof($fp)){
//读
$str=fread($fp, $buffer);
$str=str_replace("\r\n","<br/>",$str);
echo $str;
}
}
echo filegroup("test.txt");
echo fileinode("test.txt");
echo fileperms("test.txt");
clearstatcache("test.txt");
fclose($fp);

?>

转载于:https://www.cnblogs.com/kevinggk/p/6589767.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值