-1

The code bellow produce a table from a csv file

 <?php
      $lines = file('graphdata/indicfortablevsprevious.csv');  


      foreach ($lines as $lineNum => $line) {
    $cellType = ($lineNum == 0 ? "th" : "td");
    $tokens = str_getcsv($line);

    if ($lineNum == 0) echo "<thead>";
    if ($lineNum == 1) echo "<tbody>";

    echo "<tr id=\"tr" . $lineNum . "\">";

    echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
    echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
    echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
    echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
    echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";

    echo "</tr>";

    if ($lineNum == 0) echo "</thead>";
}

if (count($lines) > 1) echo "</tbody>";
    ?>

The 1st table header in the CSV is double quoted and the header in the php created table is also double quoted (Strangely the other headers are not). Is there a way to get rid of double quote in the PHP created table?

3
  • Is it possible that the source of those quotes is the csv file itself? Jan 15, 2016 at 9:42
  • The ehaders in the CSV are: "itemname","n2015Survey","2015Survey","2014Survey","Gaps Vs. Previous Survey" Only "itemname" apperas double-quoted in the PHP table Jan 15, 2016 at 9:47
  • Can you show us some of the csv raw ?
    – Pogrindis
    Jan 15, 2016 at 10:31

1 Answer 1

0

have you tried using trim($str, '"'); here $str=header of first table. try it it might work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.