Reply to Re: Line count/blank line issue with file(), etc.

Your name:

Reply:


Posted by Curtis on 12/29/05 00:47

Sean <oreilly.sean@gmail.com> wrote in message
news:1135778341.580598.160000@f14g2000cwb.googlegroups.com..
..

....

> If you have
>
> file://Numbers.txt
> 1
> 2
> 3
> 4
> 5
> 6 <-New Line here
>
> And you do print_r(file('numbers.txt')); You get =
>
> Array
> (
> [0] => 1
>
> [1] => 2
>
> [2] => 3
>
> [3] => 4
>
> [4] => 5
>
> [5] => 6
>
> )


I dug into this a bit more, Sean, thanks to your
inspiration.

The problem is one of false expectations. Doing this in my
editor:

1
2
3
4
5
<-- Cursor now here.

produces an array which looks like this:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )

In other words, there are SIX lines on the editor but only
FIVE in reality and thus in the array.

A closer look at the hex dump shows:

31 0d 0a
32 0d 0a
33 0d 0a
34 0d 0a
35 0d 0a

In other words, the newline characters are doing what
they're supposed to--throwing the cursor to the next
line--but they are DELUDING THE POOR USER (me, in this case)
into believing he has actually created a blank line.

This is OK for programmers, but no good for users.

If a user is typing a file and wants a blank line at the
end, he/she is obligated not just to press ENTER once and
place the cursor on the new line--which would make sense
from a user perspective--but to press ENTER twice. No good.
A blank line should be a blank line.

Since I'm coding to call include files, I'd say the
reasonable user expectation is to place what LOOKS like a
blank line at the end of a file, and have it show up as a
blank line when the file is read in.

file() did not allow this as I was using it, but for some
reason--I am not sure why yet--this did:

function fileget($filename)
{
$fd = fopen ($filename, "r");
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$lines[] = $buffer;
}
fclose ($fd);
return $lines;
}

Knowing what I now know, I think I could now make the file()
function work, but I'm not sure I wish to fix something that
isn't broken.

Thanks for the feedback.

--

Curtis

Visit We the Thinking
www.wethethinking.com
An online magazine/forum
devoted to philosophical
thought.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация