php删除txt文件指定行及按行读取txt文档数据的方法
向txt文件循环写入值:
- $keys= range(1,999);
- $file=<a href="/tags.php/fopen/" target="_blank">fopen</a>('key_11010000.txt',"w");
- <a href="/tags.php/foreach/" target="_blank">foreach</a>($keysas$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;