Skip to content

Instantly share code, notes, and snippets.

@amazingrando
Created April 3, 2020 17:13
Show Gist options
  • Save amazingrando/4c1ae2ebabd0a87a588d20b2d5b75698 to your computer and use it in GitHub Desktop.
Save amazingrando/4c1ae2ebabd0a87a588d20b2d5b75698 to your computer and use it in GitHub Desktop.
<?php
$csvSource = "docs/2.csv";
$csvData = [];
$csvTitles = [];
if (($handle = fopen($csvSource, "r")) !== FALSE) {
$row = 1;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
if ($row == 1) {
$csvTitles[$row][$c] = $data[$c];
}
$csvData[$row][$c] = $data[$c];
}
$row++;
}
fclose($handle);
}
$i = 2;
while ($i < count($csvData)) {
for ($c=0; $c < $num; $c++) {
$label = "<strong>" . $csvTitles[1][$c] . "</strong>: ";
$content = htmlspecialchars($csvData[$i][$c]);
echo $label . " " . $content;
echo "<br>";
}
echo "<hr>";
$i++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment