当前位置: 首页 > 后端技术 > PHP

PHP读取文件内容

时间:2023-03-29 15:15:19 PHP

$file_path="a.php";//file$file_arr=file($file_path);if(file_exists($file_path)){$file_arr=file($file_path);for($i=0;$i";fclose($file_arr);}}//freadif(file_exists($file_path)){$fp=fopen($file_path,"r");$str=fread($fp,filesize($file_path));//指定读取大小,这里读取整个文件内容取出来$str=fread($fp,filesize($file_path));//指定读取大小,这里读取整个文件内容echo$str=str_replace("\r\n","
",$str);fclose($fp);}if(file_exists($file_path)){$fp=fopen($file_path,"r");$str="";$buffer=1024;//每次读取1024字节while(!feof($fp)){//循环读取,直到读取整个文件$str.=fread($fp,$buffer);}$str=str_replace("\r\n","
",$str);回声$海峡;fclose($fp);}//file_get_contentsif(file_exists($file_path)){$str=file_get_contents($file_path);}//fgetsif(file_exists($file_path)){$fp=fopen($file_path,"r");$str="";while(!feof($fp)){$str.=fgets($fp);//逐行读取如果fgets不写length参数,默认读取1k。}$str=str_replace("\r\n","
",$str);回声$海峡;fclose($fp);}