PHP-删除标题中的双引号

时间:2016-01-15 09:26:16

标签: php css csv

下面的代码从csv文件中生成一个表

 <?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>";
    ?>

CSV中的第一个表格标题是双引号,php创建的表格中的标题也是双引号(奇怪的是其他标题不是)。有没有办法摆脱PHP创建表中的双引号?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用trim($str, '"'); $str=header of first table。尝试它可能对你有用。

相关问题