PHP implements the method of deleting spaces on the right side of an object line by line [original]

Source: Internet
Author: User
Tags rtrim
This article describes how to delete spaces on the right of a file row by row in PHP, including opening a file in php, reading files row by row, deleting spaces on the right of the rtrim function, and saving files, for more information about how to delete spaces on the right of a file row by row in PHP, see the example in this article. We will share this with you for your reference. The details are as follows:

In the process of editing and organizing the code, it is found that some code on the Internet often has a lot of spaces on the right side, which occasionally affects the code layout and reading, therefore, I wrote a simple php code to delete the space on the right of the file line by line and save it to the new file.

The demo.txt file with the right-side space (this file is the PHP row-by-row read function code) is as follows:

$ File = fopen ("welcome.txt", "r") or exit ("Unable to open file! "); // Output a line of the file until the end is reached while (! Feof ($ file) {echo fgets ($ file )."
";} Fclose ($ file );

The code for deleting spaces on the right side of PHP line by line is as follows:

<? Php $ file = @ fopen ("demo.txt", "r") or exit ("file don't exit"); $ tmpstr = ""; while (! Feof ($ file) {$ tmpstr. = rtrim (fgets ($ file )). "\ n" ;}fclose ($ file); file_put_contents ("filetmp.txt", $ tmpstr);?>

After running, you can save the files deleted from the right-side space to filetmp.txt.

Supplement:

You can edit and save files with spaces on the right in the eclipse environment, and automatically delete spaces on the right without code. More convenient.

I hope this article will help you with PHP programming.

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.