User Tools

Site Tools


kurs:php10

Übungsbeispiel:

Erstelle eine Funktion, die automatisch eine HTML-Tabelle erstellt,
welche mit Hilfe von “explode” oder “implode” die Tabelle befüllt.

<?php
// Funktion für den HTML-Dokument Start
function HTML_Kopf($titel='Titel', $farbe='ffffff'){
	print("<html><head>
		<title>$titel</title>
		</head>
		<body bgcolor='#$farbe'>");
}
// Funktion für den HTML-Dokument Ende
function HTML_Fuss(){
	print("</body>
		</html>");
}
// Funktion zur erstellung der Tabelle
function Tabelle($inhalt,$titel,$rand='0',$farbe='no',$cellpadding='0',$cellspacing='0'){
	$a_inhalt = explode(", ",$inhalt);
	$spalten  = count($a_inhalt);
	print("$spalten<br><br>");
	if(strlen($farbe) == "no"){
		print("<table border=$rand cellpadding=$cellpadding cellspacing=$cellspacing>");
	}else{
		print("<table border=$rand bgcolor=$farbe cellpadding=$cellpadding cellspacing=$cellspacing>");
	}
 
	if(strlen($titel) != 0){
		print("<th colspan=$spalten>$titel</th>");
	}
	if($spalten < 4){
		print("<tr>");
		for($i=0; $i<$spalten; $i++){
			print("<td>$a_inhalt[$i]</td>");
		}
		print("</tr></table>");
	}else{
		for($i=0; $i<$spalten; $i++){
			print("<tr><td>$a_inhalt[$i]</td></tr>");
		}
	}
}
 
HTML_Kopf('Testseite','ccffcc');
Tabelle("Hund, Katze, Maus, Floh","Fiecher",0,'#ffffff',0,5);
HTML_Fuss();
?>
kurs/php10.txt · Last modified: 2014/09/10 21:22 (external edit)