Übung 5
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHP-Kurs: Übung Telefonbuchausgabe mit Sortierung</title>
</head>
<body>
<?php
$sortierung = array();
$i = 0;
$fh = fopen("telefonbuch.inc", "r") ;
echo "<table border=1 width=\"100%\">";
echo "<tr><td><a href=\"13.php?sort=vorname\">Vorname</a></td>
<td><a href=\"13.php?sort=nachname\">Nachname</a></td>
<td><a href=\"13.php?sort=telefon\">Telefon</a></td></tr>";
while(!feof($fh)) {
$tmp = fgets($fh, 4096);
$ausgabe = explode("#", $tmp);
if($_GET["sort"] == "vorname") {
$sortierung[$i] = array($ausgabe[0], $ausgabe[0], $ausgabe[1], $ausgabe[2]);
} elseif($_GET["sort"] == "nachname") {
$sortierung[$i] = array($ausgabe[1], $ausgabe[0], $ausgabe[1], $ausgabe[2]);
} elseif($_GET["sort"] == "telefon") {
$sortierung[$i] = array($ausgabe[2], $ausgabe[0], $ausgabe[1], $ausgabe[2]);
} else {
$sortierung[$i] = array($ausgabe[1], $ausgabe[0], $ausgabe[1], $ausgabe[2]);
}
$i++;
}
asort($sortierung);
foreach($sortierung as $tmp) {
echo "<tr><td>" . htmlentities($tmp[1]) . "</td><td>" . htmlentities($tmp[2])
. "</td><td>" . htmlentities($tmp[3]) . "</td></tr>\n";
}
echo "</table>";
fclose($fh);
echo $_GET["sort"];
?>
</body>
</html>