0

I'm trying to use an html table with tabs and fill each tab with php content. Here's my code so far: ...

<html>
<body>
<!--div class="tab"
  <button class="tablinks" onclick="openCity(event, 'October')">October</button>
  <button class="tablinks" onclick="openCity(event, 'November')">November</button>
  <button class="tablinks" onclick="openCity(event, 'December')">December</button>
/div

<div id="October" class="tabcontent">
<? php
$filepath = '\data\2020_10_data';
if (file_exists($filepath)) {
    $file = fopen($filepath, 'r');
    echo "<table>
    <table border=1>
    <tr>
      <th>Date</th>
      <th>Time</th>
      <th>Who </th>
      <th>Action</th>
      <th>Rule</th>
      <th>Attribute</th>
    </tr>";
    
    while (!feof($file)) {
        $line = fgets($file);
        $first_char = $line[0];
        if ($first_char != '*' && $first_char != '^' && trim($line) != '') {
            if (strstr($line, ',')) {
                $split = explode(',', $line);
                echo "<tr>";
                foreach($split as $line) {
                    echo "<td>".$line."</td>";
                }
                echo "</tr>";
            } else {
                echo "<tr><td>".$line."</td></tr>";
            }
        }
    }
    echo "</table>";
} else {
    echo "the file does not exist";
}
?>
</div>

</body>
</html>

...

The tabs and table headers within the tab are displayed properly. But instead of filling the table with the content of the file the source code is written on the the page. I tested thr php part alone and it worked fine and displayed a table with the file content. I'm probably just missing something small but I can't find it. Any ideas?

Michele
  • 15
  • 2
  • 1
    If it's displaying the code, is it named correctly as a `.php` extension, or is the server configured to process whatever extension it has for PHP code? And can you have a space in ` php`, is it valid that way? Doesn't seem to be, on a quick test. – droopsnoot Oct 20 '20 at 11:42
  • I'm using xampp on my computer to test the page. I can upload it to a proper Apache tomorrow. However, a different .php page is diplayed correctly on my xampp Apache so I assumed there is a problem with the actual code. Edit: Yes, the space between ? and php was the problem. Code is now gone from page. Thanks! – Michele Oct 20 '20 at 15:29

0 Answers0