Skip to content

Instantly share code, notes, and snippets.

@teolopez
Last active April 26, 2022 02:24
Show Gist options
  • Save teolopez/d16fe097b869afc71e2f to your computer and use it in GitHub Desktop.
Save teolopez/d16fe097b869afc71e2f to your computer and use it in GitHub Desktop.
fgetcsv – csv to html table
<table class="table table-bordered table-condensed table-hover">
<?php
$row = 1;
ini_set('auto_detect_line_endings',TRUE);
if (($handle = fopen("http://docs.shopify.com/manual/your-store/products/product_template.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<tr>";
for ($c=0; $c < $num; $c++) {
if ($row == 1) {
echo "<th>" . $data[$c] . "</th>\n";
} else {
echo "<td>" . $data[$c] . "</td>\n";
}
}
echo "</tr>\n";
$row++;
}
ini_set('auto_detect_line_endings',FALSE);
fclose($handle);
}
?>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment