PHP implements the method of deleting spaces on the right of an object row by row. _ PHP Tutorial

Source: Internet
Author: User
PHP implements the method of deleting spaces on the right of an object row by row ,. PHP implements the method of deleting spaces on the right of a file row by row. This article describes how PHP deletes spaces on the right of a file row by row. Share it with you for your reference. The details are as follows: the method for deleting spaces on the right side of a file row by row is original in PHP,

This example describes how to delete spaces on the right of an object row by row in PHP. 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.

Articles you may be interested in:
  • Php deletes spaces on the left and right sides
  • In php, ltrim (), rtrim (), and trim () delete character space instances
  • In php, there are three ways to delete spaces in the string.
  • Php file writing, deletion, and copying methods
  • Php deletes duplicate rows in a text file
  • Php ftp operation code (upload, copy, move, delete file/Create directory)

The example in this article describes how PHP can delete spaces on the right side of an object row by row. Share it with you for your reference. The details are as follows...

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.