php读取文件内容的三种可行方法示例介绍

网络编程 发布日期:2024/10/27 浏览次数:1

正在浏览:php读取文件内容的三种可行方法示例介绍
php读取文件内容的三种方法:

//**************第一种读取方式*****************************
复制代码 代码如下:
header("content-type:text/html;charset=utf-8");
//文件路径
$file_path="text.txt";
//判断是否有这个文件
if(file_exists($file_path)){
if($fp=fopen($file_path,"a+")){
//读取文件
$conn=fread($fp,filesize($file_path));
//替换字符串
$conn=str_replace("\r\n","<br/>",$conn);
echo $conn."<br/>";
}else{
echo "文件打不开";
}
}else{
echo "没有这个文件";
}
fclose($fp);

//*******************第二种读取方式***************************
复制代码 代码如下:
header("content-type:text/html;charset=utf-8");
//文件路径
$file_path="text.txt";
$conn=file_get_contents($file_path);
$conn=str_replace("\r\n","<br/>",file_get_contents($file_path));
echo $conn;
fclose($fp);

//******************第三种读取方式,循环读取*****************
复制代码 代码如下:
header("content-type:text/html;charset=utf-8");
//文件路径
$file_path="text.txt";
//判断文件是否存在
if(file_exists($file_path)){
//判断文件是否能打开
if($fp=fopen($file_path,"a+")){
$buffer=1024;
//边读边判断是否到了文件末尾
$str="";
while(!feof($fp)){
$str.=fread($fp,$buffer);
}
}else{
echo "文件不能打开";
}
}else{
echo "没有这个文件";
}
//替换字符
$str=str_replace("\r\n","<br>",$str);
echo $str;
fclose($fp);
读取INI配置文件的函数:
$arr=parse_ini_file("config.ini");
//返回的是数组
echo $arr['host']."<br/>";
echo $arr['username']."<br/>";
echo $arr['password']."<br/>";
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。