为什么我的桌子不显示


Why is my table not showing?

我的网站出现了一些问题。它使用HTML和嵌入式PHP。我有一个时间表页面,它从CSV文件中提取信息,并将其显示为网站上的表格,以便更容易地更新时间表,但由于某些原因,它不起作用。这是代码(我删掉了不重要的东西)。

<html>
<head>
</head>
<body>
<table>
<?php
     $f = fopen("schedule.csv", "r");
     while (($line = fgetcsv($f)) !== false)
     {
          $row = $line[0]; // We need to get the actual row (it is the first element in a 1-element array)
          $cells = explode(";",$row);
          echo "<tr>";
          foreach ($cells as $cell)
          {
               echo "<td>" . htmlspecialchars($cell) . "</td>";
          }
          echo "</tr>'n";
     }
     fclose($f);
?>
</table>
</body>
</html>

然而,当我尝试打开网页时,我得到的只是:

foreach ($cells as $cell) { echo ""; } echo "'n"; } fclose($f); ?>
" . htmlspecialchars($cell) . "

我不知道是不是漏掉了一个标点符号。我基本上是从另一个程序员推荐给别人的网站上复制的,所以我不知道出了什么问题。

尝试使用以下代码:

 $f = fopen("schedule.csv", "r");
 while (($line = fgetcsv($f)) !== false)
 {
      echo "<tr>";
      foreach ($line as $cell)
      {
           echo "<td>" . htmlspecialchars($cell) . "</td>";
      }
      echo "</tr>";
 }
 fclose($f);

使用单引号代替

<html>
<head>
</head>
<body>
<table>
<?php
     $f = fopen('schedule.csv', 'r');
     while (($line = fgetcsv($f)) !== false)
     {
          $row = $line[0]; // We need to get the actual row (it is the first element in a 1-element array)
          $cells = explode(';',$row);
          echo '<tr>';
          foreach ($cells as $cell)
          {
               echo '<td>' . htmlspecialchars($cell) . '</td>';
          }
          echo '</tr><br/>';
     }
     fclose($f);
?>
</table>
</body>
</html>