文件读取 fread 函数 参数$fd,$file_size;
获取文件的大小 filesize($path); 参数$path 文件路径;
字符串替换 str_replace("\r\n","<br>",$con_str);
<?php header("content-type:text/html;charset=utf-8"); #1. 定义文件路径 $file_full_path = "F:/test.txt"; if(file_exists($file_full_path)){ #2.打开文件fopen $fd = fopen($file_full_path,'r'); #3.读取文件大小 $file_size = filesize($file_full_path); $con_str = fread($fd,$file_size); //及时关闭文件!!!重要 数据采集 MFC fclose($fp); // str_replace 正则替换字符串的。。 $con_str = str_replace("\r\n","<br>", $con_str); #4.读取文件 echo $con_str; }
文件过大处理方法 feof($fd);
while()
<?php
header("content-type:text/html;charset=utf-8");
#1. 定义文件路径
$file_full_path = "F:/test.txt";
if(file_exists($file_full_path)){
#2.打开文件fopen
$fd = fopen($file_full_path,'r');
#3.读取文件大小
$file_size = filesize($file_full_path);
$buffer = '';
$buffer_size = 1024;
$con_str = '';
while (!feof($fd)){
$buffer = fread($fd,$buffer_size);
$con_str = $buffer.$con_str;
}
//及时关闭文件!!!重要 数据采集 MFC
fclose($fd);
// str_replace 正则替换字符串的。。
$con_str = str_replace("\r\n","<br>", $con_str);
#4.读取文件
echo $con_str;
}
配置文件 ini 用法
函数 pase_init_file($filepath); 返回值是数组
<?php
header("content-type:text/html;charset=utf-8");
$file_path = 'config.ini';
$arr_ini = parse_ini_file($file_path);
var_dump($arr_ini);
echo "<br>用户名".$arr_ini['user'];
echo "<br>密码".$arr_ini['password'];