Welcome to the Safari Gallery
Select an animal to discover a fun facts.
LionTiger
Giraffe
Zebra
CODE FOLLOWS
<?php
include('../includes/header.php');
error_reporting(E_ALL); // set error reporting to all
// array of animals for gallery
$animals = array("lion", "tiger", "giraffe", "zebra");
echo "<h1>Welcome to the Safari Gallery</h1>";
echo "<p>Select an animal to discover a fun facts.</p>";
// loops through the animal list
foreach ($animals as $animal) {
// connecting text and images
echo "<a href='?animal=$animal' class='animalbtn'>" . ucfirst($animal) . "</a> ";
echo "<br><br>";
}
// check if an animal was selected
if (isset($_GET['animal']))
{
$animal = basename($_GET['animal']);
// path to images and texts of animals
$img = "../safari/" . $animal . ".png";
$txt = "../safari/" . $animal . ".txt";
echo "<hr>";
echo "<h2>" . ucfirst($animal) . "</h2>";
// check if the text file exists and read its contents
if (file_exists($img))
{
echo "<img src='$img' width='350'><br><br>";
}
if (file_exists($txt))
{
$fact = file_get_contents($txt); // reads animal text
echo "<p>$fact</p>"; // displays text
}
}
include('../includes/footer.php');
?>