tdphp/td4/td4b/exo1.php
2023-03-22 00:13:04 -07:00

56 lines
No EOL
2 KiB
PHP
Executable file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<?php
// Ouvre le fichier menu.txt en mode lecture
$menu_file = fopen("menu.txt", "r") or die("Impossible d'ouvrir le fichier menu.txt");
// Lit les lignes du fichier une à une
$menu_items = array();
while (!feof($menu_file)) {
$line = fgets($menu_file);
if ($line) {
// Sépare la ligne en deux parties : le titre et l'URL
$parts = explode(" ", $line);
$title = $parts[0];
$url = $parts[1];
// Ajoute un élément au tableau de menu
$menu_items[] = array("title" => $title, "url" => $url);
}
}
// Ferme le fichier
fclose($menu_file);
// Affiche la barre de menu
echo "<nav class='navbar navbar-expand-lg navbar-light bg-light'>";
echo "<div class='container-fluid'>";
echo "<a class='navbar-brand' href='#'>Menu</a>";
echo "<button class='navbar-toggler' type='button' data-bs-toggle='collapse' data-bs-target='#navbarNav' aria-controls='navbarNav' aria-expanded='false' aria-label='Toggle navigation'>";
echo "<span class='navbar-toggler-icon'></span>";
echo "</button>";
echo "<div class='collapse navbar-collapse' id='navbarNav'>";
echo "<ul class='navbar-nav'>";
foreach ($menu_items as $item) {
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='" . $item["url"] . "'>" . $item["title"] . "</a>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</div>";
echo "</nav>";
?>
</body>
</html>