|
发表于 2019-5-21 12:11:57
|
显示全部楼层
- <?php
- function readTxt($name,$rln){
- $file = fopen($name,"r");
- $data = [];
- for($n=0;$n<$rln;$n++){
- $s = fgets($file);
- array_push($data,$s);
- }
- fclose($file);
- return $data;
- }
- function delTxt($name,$rln){
- $items = file($name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($items as $key => $item) {
- if($key >= $rln){
- $new[] = $item;
- }
- }
- if ($new) {
- // Write file with $new content
- file_put_contents($name, implode("\n", $new));
- }
- }
- $rln = 10;
- $rt = readTxt('abc.txt',$rln);
- delTxt('abc.txt',$rln);
- var_dump($rt);
- ?>
复制代码
添加一个按钮 调用delTxt删除 |
|