本文实例讲述了php编程实现追加内容到txt文件中的方法。分享给大家供大家参考,具体如下:
覆盖txt文件内容:
1
2
3
4
|
$filename = "aa/a.txt" ;
$handle = fopen ( $filename , "w" );
$str =fwrite( $handle , "test" );
fclose( $handle );
|
效果:
1
|
testtesttesttesttesttesttest
|
追加内容到txt:
1
2
3
4
|
$filename = "aa/a.txt" ;
$handle = fopen ( $filename , "a+" );
$str =fwrite( $handle , "test\n" );
fclose( $handle );
|
效果:
1
2
3
4
5
6
7
|
test
test
test
test
test
test
test
|
逐行读取txt :
1
2
3
4
5
|
$lines =file( "db.txt" );
foreach ( $lines as $value ) {
$line = explode ( "," , $value );
echo "no1:$line[0]--no2:$line[1]---time:$line[2]-<br>" ;
}
|
希望本文所述对大家PHP程序设计有所帮助。
原文链接:http://blog.csdn.net/k8080880/article/details/45168719