The content of each "$tok" is being wrapped by a "tr" element. A "tr"
element in html can not contain content directly, just table cell
elements (td or th usually). So your browser finds text in an illegal
place, and places it before the table (other browsers might do other
things with it).
Try on of the following:
while ( $arr = fgetcsv( $fileh ) ) {
echo "<tr>";
for ( $tok in $arr )
echo "<td>$tok</td>"
echo "</tr>";
}
or
> while ($text = fgets($fileh)) {
echo "<tr>\n";
> $tok = strtok($text, ",");
> while ($tok !== FALSE) {
> echo "<td>" . $tok . "</td>\n";
> $tok = strtok(",");
> }
echo "</tr>\n";
> }
Note also that your code will split a csv field that contains a comma in
text, eg for the following two csv fields:
"this is text, and text, and text","this,is,more,text"
Your code will generate 7 table cells from the two csv fields.
This may be what you want, or it may not. Your code will also include the
" marks in the output, which might not be what you want?
Rgds
Denis McMahon