|
Posted by Curtis on 12/28/05 09:38
J.O. Aho <user@example.net> wrote in message
news:41ec8sF1e2eotU1@individual.net...
> Curtis wrote:
> > Sorry I didn't make myself clear. I'm not simply dumping
> > this to an HTML file.
> >
> > That should not make any difference, J.O. Please not
that
> > I'm only displaying the COUNT of the lines, not the
lines
> > themselves.
> >
> > The point was that file() seems to be eating THE LAST
> > appended newline--it does not show up in the count.
> >
> > In fact, in my code I'm converting all
forms/combinations of
> > newline to \r, processing the stuff, then converting any
\r
> > that's left over at the end to \n<br /> tags, to display
> > properly as both HTML source and viewed HTML.
> >
>
> --- from
http://www.php.net/manual/en/function.file.php ---
> Note: If you are having problems with PHP not recognizing
the line endings
> when reading files either on or created by a Macintosh
computer, you might
> want to enable the auto_detect_line_endings run-time
configuration option.
> --- eof ---
I'm creating the files myself, and checked the coding with a
hex dump in my editor. Near as I can tell, they're exactly
what they should be, with no weirdness. The last newline is
simply a 0a hex, and that's what file() is ignoring.
>
> I _guess_ the problem here is that you convert the newline
to '\r', which is
> really a carrier return, move the cursor to the start of
the line, what you
> want to do is to move the cursor to the next line, which
happens to be '\n'.
> I know that Microsoft do use the '\n\r' (or is it '\r\n')
for newline, but
> it's quite alone about that, so better to stick with
others uses or try the
> trick that seems to help the other microsoft (Apple).
This problem happens before ANY conversion, though. If you
read my OP, you can see that the number of lines read is
wrong right after the file read--not so with fgets() though.
As for the processing, I convert all \n\r and \r\n
combinations to \r, then I convert all remaining \n lines to
\r. This is strictly for programmatic reasons, so the
software can turn some text into \n\<tag> and \n\<p... and
all the \r left over get converted into \n\<br> tags. The
selection of \r is not terribly significant--I could as
easily use \01 or \02 or some low ASCII value like that
instead of \r. The choice of \r was simply because it is
associated with newlines and easier to understand in the
code.
My code should have no problem with whatever form the
newlines take-- Apple, Microsoft, or whatever--\r\n, \n\r,
or plain \n. But as I noted, the last \n line is lost right
out of file().
--
Curtis
Visit We the Thinking
www.wethethinking.com
An online magazine/forum
devoted to philosophical
thought.
Navigation:
[Reply to this message]
|