Simple 2 file news website

<!DOCTYPE html>

<html lang=”en”>

<head>

<meta charset=”UTF-8″>

<title>News Website</title>

<style>

body {

font-family: Arial, sans-serif;

margin: 20px;

}

h1 {

color: #333;

}

.table-container {

overflow-x: auto;

}

table {

width: 100%;

border-collapse: collapse;

min-width: 600px;

}

th, td {

border: 1px solid #999;

padding: 10px;

text-align: left;

}

th {

background-color: #f2f2f2;

}

</style>

</head>

<body>

<h1>News Website</h1>

<div class=”table-container”>

<table>

<tr>

<th>What</th>

<th>When</th>

<th>Where</th>

<th>Who</th>

<th>Why</th>

</tr>

<?php

$filename = “news.csv”;

if (file_exists($filename) && ($handle = fopen($filename, “r”)) !== FALSE) {

// Skip the header row

fgetcsv($handle);

// Read and output the rest of the rows

while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {

echo “<tr>”;

foreach ($data as $cell) {

echo “<td>” . htmlspecialchars($cell) . “</td>”;

}

echo “</tr>”;

}

fclose($handle);

} else {

echo “<tr><td colspan=’5′>Error: news.csv not found or unreadable.</td></tr>”;

}

?>

</table>

</div>

</body>

</html>

Leave a comment