You are here: Re: Line count/blank line issue with file(), etc. « All PHP « IT news, forums, messages
Re: Line count/blank line issue with file(), etc.

Posted by Sean on 12/28/05 15:59

If you have

//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

)

Again look at "6 <-New Line here". To the file function this is
going to be treated as 1 element. If it was 540A0A it would be
different. Why? Because that is what the file function does.

Please read again, "Note: Each line in the resulting array will
include the line ending, so you still need to use rtrim() if you do not
want the line ending present."

In a text editor it comes up as having a new line after 6 but the new
line character is on the same line as 6.

Now do you get this example?
//numbers.txt
1
2
3

5
6
7

Between 3 and 5 there are 2 new line characters in the middle of the
file. So that's why you get.
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] =>
[4] => 5
[5] => 6
[6] => 7
)
Except if the last line was 0A0A it would be treated as one element in
the array.

 

Navigation:

[Reply to this 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

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