Home > Backend Development > PHP Tutorial > PHP method to delete spaces on the right side of files line by line Original, _PHP tutorial

PHP method to delete spaces on the right side of files line by line Original, _PHP tutorial

WBOY
Release: 2016-07-12 09:02:47
Original
711 people have browsed it

How to delete spaces on the right side of a file line by line in PHP. Original,

This article describes an example of how to delete spaces on the right side of a file line by line in PHP. Share it with everyone for your reference, the details are as follows:

In the process of editing and organizing the code, I found that some codes on the Internet often have a lot of spaces on the right side, which occasionally affects the layout and reading of the code, so I wrote a simple PHP code to delete the right side of the file line by line. spaces and save to a new file.

The demo.txt file with spaces on the right (this file is the PHP line-by-line reading 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). "<br />"; 
} 
fclose($file); 

Copy after login

The code for PHP to delete spaces on the right line by line is as follows:

<&#63;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);
&#63;>

Copy after login

After running, the file with the spaces on the right deleted can be saved to filetmp.txt

Supplement:

You can also edit and save files with spaces on the right in the eclipse environment, and the spaces on the right can be automatically deleted without coding. More convenient.

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • How to delete left and right spaces in php
  • Examples of ltrim(), rtrim() and trim() in php to delete character spaces
  • 3 ways to delete spaces in strings in php
  • How to write, delete and copy files in php
  • How to delete duplicate lines in text files in php
  • PHP FTP operation code (upload, copy, move, delete files/create directories)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084537.htmlTechArticleThe method of PHP to delete the spaces on the right side of the file line by line is original. This article describes the example of PHP realizing the deletion of the right side of the file line by line. side space method. Share it with everyone for your reference, the details are as follows: In...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template