FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » SplFileObject always returns an extra "last" line -- why?
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Return to the default flat view Create a new topic Submit Reply
SplFileObject always returns an extra "last" line -- why? [message #186318] Tue, 24 June 2014 10:09 Go to previous message
kurtk(at)pobox(dot)com is currently offline  kurtk(at)pobox(dot)com
Messages: 10
Registered: May 2012
Karma:
Junior Member
add to buddy list
ignore all messages by this user
Why does SplFileObject always seems to return an extraneous, final empty string as an extra last line of file.

If I have a file with only one line of text and run this code

try {
$file = new SplFileObject("./one.txt");

} catch (Exception $e) {
echo $e->getMessage() . "\n";
}

foreach($file as $line_no => $contents) {

echo "line number " . $line_no . " is: " . $contents;

}

I get two lines of output:
line number 0 is: one
line number 1 is:

The file one has one line of text, the word "one". I'm running this on Linux Mint 17 with PHP 5.5.9.

Thanks
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Putting it all together
Next Topic: encoding
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Oct 22 11:43:27 EDT 2017

Total time taken to generate the page: 0.00650 seconds