fgetcsv返回太多条目

I have the following code:

while (!feof($file)) {
        $arrayOfIdToBodyPart = fgetcsv($file,0, "\t");
            if (count($arrayOfIdToBodyPart)==2){

the problem is, the contents of the file look like this:

39      ankle
40      tibia
41      Vastus Intermedius

and so on

sometimes, the test in the if will show three entries, with the first being the number, the second being the name, and the third being just... emtpy.

This causes the if block to fail, and me to be sad. I know i can just make the if block test for >=2, but is there any way i can get it to just recognise the fact that there are two items? I don't like that the fgetcsv is finding "mystery" characters at the end of the line.

Is this possibly a unix server running a windows-based file error? If so, and i'm running an ubuntu server without dos2unix, where do i get it?

You probably have tabs at the end of a line:

value<tab>value<tab><newline>

If that's the case, dos2unix won't help you. You might have to do something like read each line into a variable, trim() the variable, and then use str_getcsv() to split it.

Is it possible that you have a tab at the end of those lines? They are invisible and often hard to spot... you might want to double check.

Also if you are working with csv files, while you are running windows locally and the server is unix, I found this line:

ini_set('auto_detect_line_endings', true);

saves a lot of headaches.