/**
* 写入文件并换行
*/
private function riteTxt(){
//文件路径
$file = storage_path('logs/data.txt');
//打开文件
$openFile = fopen($file,"w");
//测试写入并换行
for ($i = 1;$i <= 10;++$i) {
fwrite($openFile, "{$i}\r\n");
}
fclose($openFile);
}
/**
*逐行读取TXT文件
* @params file $txtfile [带读取的文件]
*/
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;
}