Link to home
Create AccountLog in
Avatar of maccaj51
maccaj51Flag for Afghanistan

asked on

CSV and Row Splitting

Hi Experts,

I have been on this for about 24 hours now and not getting anywhere.

I need to import a CSV file...
Split it into rows...
Split it into columns...
Apply a different html format to the first row...

Could some please help!!!

Many Thanks
Avatar of Php_expert
Flag of India image

Avatar of Julian Hansen
Take a look at the php fgetcsv function

If you would like some code post more info about what you are trying to do.
Avatar of maccaj51


Hi Julian,

Thats what ive been working from...

Im trying to take a csv file... and put it into this format... By:

1) Splitting it into rows
2) Putting first row in thead
3) Putting remaining rows in tbody

Any Ideas? Ive been miserably unsuccessful!


Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Ray,

MANY MANY thanks for that.

However they all output as <th>'s...

It cant distinguish between rows?
Uhh, I think only the top row is <th>, right?
My thinking is along these lines:

Does that make sense to you, or am I missing some part of the question?
Is it possible to set an integer to break each line off at?
Thats exactly right in your code the first line is <th> and the rest of the lines are <td>...

However it only outputs <th> from my csv file...

Suggesting it cant recognise where each row starts and ends?
Hero... just needed :
ini_set("auto_detect_line_endings", true);
Interesting.  I do not have that setting on in my server, but it seems to work just fine.   Maybe it has something to do with the differences in EOL characters between operating systems.  You might want to try reading with file() also to see how that works.

Anyway, it's a good question.  Thanks for the points, ~Ray