dongmei6426 2016-05-13 06:22
浏览 25

为什么我的桌子没有显示?

I'm having some trouble with my website. It uses HTML with embedded PHP. I have a schedule page that pulls information from a CSV file and displays it as a table on the site, to make it easier to update schedules, but it's not working for some reason. Here's the code (I cut out the unimportant stuff).

<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>
";
     }
     fclose($f);
?>
</table>
</body>
</html>

However, when I try opening the webpage, all I get is:

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

" . htmlspecialchars($cell) . "

I can't tell if I'm missing a punctuation or what. I basically copied it from another site that another programmer recommended to someone else, so I don't know what's wrong.

  • 写回答

2条回答 默认 最新

  • duanche2007 2016-05-13 06:37
    关注

    Use single quotes instead

    <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>
    
    评论

报告相同问题?