How to delete the last line in the txt file ]?

Source: Internet
Author: User
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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.