How to delete the last line in the txt file ]?? Fwrite ($ flietxt, $ txt); fclose ($ flietxt); the last row is always empty. sometimes the last row is always empty when you select a random row, and errors may easily occur. is there any way to delete the last row ..., try this and solve similar problems in the future. PHPcode $ tem how to delete the [last line] in the txt file ]??
Fwrite ($ flietxt, $ txt );
Fclose ($ flietxt );
The last row is always empty. sometimes the last row is always empty at random. it is prone to errors. Is there any way to delete the last row...
------ Solution --------------------
Try this and solve similar problems in the future.
PHP code
$ Temp = array (); while ($ r = $ empire-> fetch ($ SQL) {$ titleurl = sys_ReturnBqTitleLink ($ r ); $ txt = $ r ['id']. '| '. $ r ['title']. '| '. $ titleurl. '| '. $ r ['newstime']. '| '. $ r ['titlepic ']; // fwrite ($ flietxt, $ txt); $ temp [] = $ text;} fwrite ($ flietxt, implode ("\ n ", $ temp); fclose ($ flietxt );
------ Solution --------------------
You can make this problem so complicated.
Nagging
Fwrite ($ flietxt, trim ($ txt ));
You are afraid that there is no line break
Then you can
Fwrite ($ flietxt, trim ($ txt). "\ n ");
------ Solution --------------------
Remove the \ n at the end of the txt file. just go upstairs.
------ Solution --------------------
Print $ txt.
------ Solution --------------------
The title of your question is: how to delete the [last line] in the txt file]
Only
Fwrite ($ flietxt, $ txt );
Fclose ($ flietxt );
Two lines of code
I will answer you fwrite ($ flietxt, trim ($ txt ));
Is there anything wrong? For multi-line text, you only need to delete the last line break.
For the problem of #2 derivation, we need to analyze the specific situation
That is, the branch successively writes the file.
If you do not need to write line breaks in the last line, it is complicated to judge.
However, if the problem is reversed, the problem will be simple.
PHP code
$lr = '';while($r=$empire->fetch($sql)){ fwrite($flietxt, $lr . trim($txt) ); $lr = PHP_EOL;}