本文实例讲述了php删除txt文件指定行及按行读取txt文档数据的方法。分享给大家供大家参考,具体如下:
向txt文件循环写入值:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$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文档数据:
1
2
3
4
5
6
7
8
9
|
$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 ; |
希望本文所述对大家PHP程序设计有所帮助。