How to remove a line from text file using php without leaving an empty line
问题 currently I am able to remove a specific line from text file using php. However, after removing that line, there will be an empty line left behind. Is there anyway for me to remove that empty line so that the lines behind can move up? Thank you for your help. 回答1: $DELETE = "the_line_you_want_to_delete"; $data = file("./foo.txt"); $out = array(); foreach($data as $line) { if(trim($line) != $DELETE) { $out[] = $line; } } $fp = fopen("./foo.txt", "w+"); flock($fp, LOCK_EX); foreach($out as