欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php讀取文件內(nèi)容的三種可行方法示例介紹

 更新時間:2014年02月08日 15:40:17   作者:  
這篇文章主要介紹了php讀取文件內(nèi)容的三種方法,需要的朋友可以參考下
php讀取文件內(nèi)容的三種方法:

//**************第一種讀取方式*****************************
復制代碼 代碼如下:

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);

//******************第三種讀取方式,循環(huán)讀取*****************
復制代碼 代碼如下:

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配置文件的函數(shù):
$arr=parse_ini_file("config.ini");
//返回的是數(shù)組
echo $arr['host']."<br/>";
echo $arr['username']."<br/>";
echo $arr['password']."<br/>";

相關文章

最新評論