note 84061 added to function.fgets
| From: | julian dot chappell at NOSPAM dot btopenworld dot com | Date: | Thu, 26 Jun 2008 03:14:00 +0000 |
| Subject: | note 84061 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140823@lists.php.net to get a copy of this message | ||
Reply to Jerem's note. fgets terminating on chr(10) is correct.
For the sake of you youngsters who have never heard of such things, the protocol for the CRLF pair
dates back to the days where the input/output with computers was on teletype machines. A sort of
glorified typewriter.
chr(13) is a carriage return (CR), a command which physically moved the type head to the home
position and chr(10) is a line feed (LF), which moved the paper up a line.
The standard order in which these were used was CRLF - chr(13)/chr(10) - and both were needed for a
line break. Use a CR chr(13) on its own and you would overwrite the beginning of the same line.
(Incidentally, this was how bold type was done - print the same thing in the same place twice!). Use
LF chr(10) on its own and you would continue printing at the current position across the page but
dropped down a line. (Because the paper would move up but the print head remain where it is).
Usage of this protocol has become somewhat sloppy and ill-defined these days for both printers and
monitors. Some applications expect a line feed chr(10) on its own and simply assume a carriage
return, others still use both but often without observing their distinctly separate functions. So
much so that it may sometimes appear that they both do more or less the same thing, you only need
one of them, and which to use is purely a matter of personal choice. Wrong on all counts!
fgets terminating on a LF chr(10) is correct as it ensures that the preceding CR chr(13) is included
in the line if it is present - and doesn't matter if it isn't. If fgets ever terminated on
CR chr(13) as jerem suggests more often than not there would be a LF at the beginning of the next
line read.
The prefered use of chr(13) alone as a line break is risky. You might get away with it using your
own applications and current printer, but if your file is for general release other people would see
the entire output of your file printed on the same line if they use applications that interpret the
CRLF pair more correctly. Not what you intended!
----
Server IP: 92.48.100.16
Probable Submitter: 86.128.182.209
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- https://master.php.net/note/edit/84061
Del: integrated -- https://master.php.net/note/delete/84061/integrated
Del: useless -- https://master.php.net/note/delete/84061/useless
Del: bad code -- https://master.php.net/note/delete/84061/bad+code
Del: spam -- https://master.php.net/note/delete/84061/spam
Del: non-english -- https://master.php.net/note/delete/84061/non-english
Del: in docs -- https://master.php.net/note/delete/84061/in+docs
Del: other reasons-- https://master.php.net/note/delete/84061
Reject -- https://master.php.net/note/reject/84061
Search -- https://master.php.net/manage/user-notes.php