代码语言:javascript复制
<?php
/*
* 逐行读取TXT文件
*/
function getTxtcontent($txtfile){
$file = @fopen($txtfile,'r');
$content = array();
if(!$file){
return 'file open fail';
}else{
$i = 0;
while (!feof($file)){
$content[$i] = mb_convert_encoding(fgets($file),"UTF-8","GBK,ASCII,ANSI,UTF-8");
$i ;
}
fclose($file);
$content = array_filter($content); //数组去空
}
// return $content;
var_dump($content) ;
}
getTxtcontent('1.txt');
同个目录下的1.txt内容:
代码语言:javascript复制2
56
897654
nbvhfghfh,5656