trailing blank line in a text file

Lew Bloch conrad at lewscanon.com
Wed Jul 21 12:26:47 UTC 2004


> Yes, I agree with you - I can either adjust the code or get back to my
> original question.  :)  How do I get an editor to not insert the trailing
> blank line ( LF line) rather than add it (with such editors as vi and
> nano)?

You do not have a trailing blank line 4, as Craig pointed out.  You have a 
file with three lines, not 4, each ending in '\n'.  The4re is no trailing 
blank line.  You cannot solve this, because the problem does not exist. The 
file only has 3 lines, not 4.

Your editor does not insert a trailing blank line.  It displays an illusion 
of a fourth line, which does not exist in the three-line file it displays. 
The file itself only contains three lines.

Sometimes to solve a problem you have to ask yourself the correct question. 
In this case, you are trying to eliminate a phantom fourth line that does not 
exist, so you cannot eliminate it.  There are only three lines in the file. 
Perhaps a better question to ask yourself is, "Which editor will not seem to 
display a phantom fourth line?"

The answer is, "No good editor."  The newline is the last character of the 
file, therefore the last character displayed.  When the cursor moves past the 
last character, a newline, it seems to be positioned on the fourth line, but 
it's not, because there is no fourth line.  It's positioned at the point just 
past the last character in the file, a newline, which appears at the end of 
the third line of the three-line file.  This is, in 99 44/100 % of the cases, 
just exactly what one wants an editor to do.

So accept the fact that the file only has three lines and ask yourself a 
different question, such as how to rewrite the PHP to count lines correctly.





More information about the users mailing list