I am trying to read/parse a .csv file, but when I output to the borwser all I get is machine code. Here is the code I am using to read and output the file.

$handle = fopen("report.csv", "r");
while ($data = fgetcsv($handle, 2000, ","))
{
foreach ($data as $key => $value)
{
echo "$key - $value<Br>";
}

}
fclose($handle);

seems pretty straight forward but am I missing something here? Thanks in advance.

    $fp = fopen("test.txt", 'r');//as read only
    if($fp){
       while(!FEOF($fp)){//read till end of file reached
            $record = fgets($fp);//read one line at a time
            $arr_field = explode(',', $record);//get each field
            $no_elem = sizeof($arr_field);
            echo $no_elem.'<BR>';        
    } }

    havent tested it but should work, let me know...

      What do you mean "machine code"? Are you sure you're reading at a CSV file and not some other sort of file that just happens to have a .csv extension?

        Might also want to check to see if you accidently ftp'd the file in bin mode

          Write a Reply...