Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

csv always has blank line at end

Status
Not open for further replies.

gmail2

Programmer
Jun 15, 2005
987
IE
I'm writing a script to upload a csv file (with a little help from jpadie !!). However, when I use fgetcsv it always seems to read a blank line at the end of the file and I can't for the life of me figure out why. I've checked the file and there's no extra line feed at the end. Does anybody know why this is happening?
 
have you got a return character at the end of the last line of records?
 
Yea I think you might be right there actually. But I just created a new csv file in excel and it done the same thing. But if I open in notepad and then past into word and show characters it does seem like there's a carriage return at the end of the last record. I'm not overly concerned about this anyway as I've got some error trapping in there so that if the number of records in the array does not equal the number required to do the insert it just gets dumped into an errors table. Thanks for the post though
 
see my latest post on your other thread. this fixes the error-trap too.
 
testing for an array fixes the problem but is not the right or most elegant way to do this.

better to test the fgetcsv function at the start of the while loop
Code:
while ($fileContents[] = fgetcsv($fh, ",", 1000000) !=FALSE):
endwhile;

[/code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top