Jump to content

csv to html table and styling


ddellostritto

Recommended Posts

Hi All -

 

I hope that you can help me with a small problem that I have.

 

I need to display a .csv file as a html table.  I've found a script that works but it doesn't let me style it: or at least, no unique styling per every other row, bold headers, etc..

 

Can any one help me?

 

The code I have is:

<?php
echo "<html>\n<body>\n\t<table style=''>\n\n";
$f = fopen("THECSVFILE.csv", "r");
while (($line = fgetcsv($f)) !== false) {
        echo "\t\t<tr>\n";
        foreach ($line as $cell) {
                echo "\t\t\t<td style='padding:.4em;'>" . htmlspecialchars($cell) . "</td>";
        }
        echo "\r</tr>\n";
}
fclose($f);
echo "\n\t</table>\n</body>\n</html>";
?>

Link to comment
https://forums.phpfreaks.com/topic/201913-csv-to-html-table-and-styling/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.