本文实例讲述了php删除txt文件指定行及按行读取txt文档数据的方法。
向txt文件循环写入值:$keys = range(1,999);
$file = fopen('key_11010000.txt',"w");
foreach($keys as $key){
fwrite($file,"$key\r\n");
}
fclose($file);
$f1 = fopen('key_11010000.txt','r');
while(!feof($f1)){
$line=fgets($f1);
$line = trim($line);
$arr[] = $line;
}
$keys = array_filter($arr);
var_dump($keys);
按行读取txt文档数据:$f1 = fopen('key_11010000.txt','r');
while(!feof($f1)){
$line=fgets($f1);
$line = trim($line);
$arr[] = $line;
}
$keys = array_filter($arr);
var_dump($keys);
die;