PHP Scripte
Anbei einige PHP Scripte, die auf den Webseiten von Lektion1.de verwendet werden. Kommentare und Verbesserungsvorschläge nehme ich gerne entgegen.
Aussaatstärke
Ein PHP-Script zur Berechnung der Aussaatstärke. Kommentare oder Nachrichten sind herzlich Willkommen. Auch gerne zu den (Grenz-) Werten im Array, mit deren Hilfe die Plausibilitätsprüfung erfolgt. Hier das Script in Aktion.
<?php
function saat () {
// Array: Kultur, Keimfähige Körner je m² (min/max), Keimfähigkeit (min), TKG (min/max), Aussaatmenge (min/max)
$array = array ();
$array[] = array ( 'Kultur' => 'Ackerbau (allgemein)', 'kkm_min' => 30, 'kkm_max' => 900, 'kf' => 80, 'tkg_min' => 2, 'tkg_max' => 500, 'saat_min' => 20, 'saat_max' => 300 );
$array[] = array ( 'Kultur' => 'Ackerbohne', 'kkm_min' => 30, 'kkm_max' => 45, 'kf' => 85, 'tkg_min' => 400, 'tkg_max' => 500, 'saat_min' => 160, 'saat_max' => 220 );
$array[] = array ( 'Kultur' => 'Erbse (Körner)', 'kkm_min' => 60, 'kkm_max' => 80, 'kf' => 80, 'tkg_min' => 220, 'tkg_max' => 280, 'saat_min' => 150, 'saat_max' => 250 );
$array[] = array ( 'Kultur' => 'Gerste (Zweizeilig)', 'kkm_min' => 280, 'kkm_max' => 350, 'kf' => 92, 'tkg_min' => 35, 'tkg_max' => 55, 'saat_min' => 140, 'saat_max' => 180 );
$array[] = array ( 'Kultur' => 'Gerste (Vierzeilig)', 'kkm_min' => 230, 'kkm_max' => 330, 'kf' => 92, 'tkg_min' => 35, 'tkg_max' => 55, 'saat_min' => 110, 'saat_max' => 140 );
$array[] = array ( 'Kultur' => 'Gerste (Sommer)', 'kkm_min' => 300, 'kkm_max' => 350, 'kf' => 92, 'tkg_min' => 35, 'tkg_max' => 55, 'saat_min' => 120, 'saat_max' => 160 );
$array[] = array ( 'Kultur' => 'Hafer', 'kkm_min' => 250, 'kkm_max' => 380, 'kf' => 85, 'tkg_min' => 25, 'tkg_max' => 55, 'saat_min' => 80, 'saat_max' => 150 );
$array[] = array ( 'Kultur' => 'Lupine (Blau)', 'kkm_min' => 80, 'kkm_max' => 130, 'kf' => 85, 'tkg_min' => 120, 'tkg_max' => 190, 'saat_min' => 120, 'saat_max' => 250 );
$array[] = array ( 'Kultur' => 'Lupine (Gelb)', 'kkm_min' => 50, 'kkm_max' => 90, 'kf' => 85, 'tkg_min' => 110, 'tkg_max' => 180, 'saat_min' => 80, 'saat_max' => 200 );
$array[] = array ( 'Kultur' => 'Lupine (weiß)', 'kkm_min' => 60, 'kkm_max' => 70, 'kf' => 85, 'tkg_min' => 250, 'tkg_max' => 500, 'saat_min' => 140, 'saat_max' => 300 );
$array[] = array ( 'Kultur' => 'Luzerne', 'kkm_min' => 700, 'kkm_max' => 900, 'kf' => 95, 'tkg_min' => 2, 'tkg_max' => 2,5, 'saat_min' => 20, 'saat_max' => 30 );
$array[] = array ( 'Kultur' => 'Roggen (Sommer)', 'kkm_min' => 300, 'kkm_max' => 350, 'kf' => 85, 'tkg_min' => 30, 'tkg_max' => 45, 'saat_min' => 110, 'saat_max' => 170 );
$array[] = array ( 'Kultur' => 'Roggen (Winter)', 'kkm_min' => 200, 'kkm_max' => 300, 'kf' => 85, 'tkg_min' => 30, 'tkg_max' => 40, 'saat_min' => 80, 'saat_max' => 120 );
$array[] = array ( 'Kultur' => 'Sonnenblume', 'kkm_min' => 70, 'kkm_max' => 90, 'kf' => 85, 'tkg_min' => 40, 'tkg_max' => 70, 'saat_min' => 32,9411764705882, 'saat_max' => 74,1176470588235 );
$array[] = array ( 'Kultur' => 'Triticale', 'kkm_min' => 250, 'kkm_max' => 350, 'kf' => 85, 'tkg_min' => 30, 'tkg_max' => 55, 'saat_min' => 110, 'saat_max' => 170 );
$array[] = array ( 'Kultur' => 'Weizen (Hybrid)', 'kkm_min' => 150, 'kkm_max' => 200, 'kf' => 92, 'tkg_min' => 40, 'tkg_max' => 55, 'saat_min' => 75, 'saat_max' => 100 );
$array[] = array ( 'Kultur' => 'Weizen (Sommer)', 'kkm_min' => 200, 'kkm_max' => 500, 'kf' => 92, 'tkg_min' => 40, 'tkg_max' => 55, 'saat_min' => 180, 'saat_max' => 220 );
$array[] = array ( 'Kultur' => 'Weizen (Winter)', 'kkm_min' => 280, 'kkm_max' => 450, 'kf' => 92, 'tkg_min' => 40, 'tkg_max' => 55, 'saat_min' => 160, 'saat_max' => 220 );
$array[] = array ( 'Kultur' => 'Sonstige', 'kkm_min' => 30, 'kkm_max' => 900, 'kf' => 80, 'tkg_min' => 2, 'tkg_max' => 500, 'saat_min' => 20, 'saat_max' => 300 );
// Formular
$saat = '';
$saat .= "<form action=\"" . htmlspecialchars($_SERVER["PHP_SELF"]) . "#ass\" method=\"post\" id=\"form_saat\">";
// Auswahl Fruchtart
$saat .= "\n<fieldset>";
$saat .= "\n<legend>Auswahl</legend>";
$saat .= "\n<select name=\"send_frucht\" size = \"1\" id=\"send_frucht\" autofocus>";
for ( $i = 0; $i < count ($array); $i++ ) {
$saat .= "\n<option value=\"" . $array [$i]['Kultur'] . "\"";
if ( !empty ( $_POST['send_frucht'] ) and $array [$i]['Kultur'] == $_POST['send_frucht'] )
$saat .= ' selected';
$saat .= ">" . $array [$i]['Kultur'] . "</option>";
}
$saat .= "\n</select><br>";
$saat .= "\n<label for=\"post_tag\">Kultur</label><br>";
// Ausgewählte Felder nach abschicken
if ( !empty ( $_POST['send_kkm'] ) and !empty ( $_POST['send_tkg'] ) and !empty ( $_POST['send_kf'] ) ) {
$place_kkm = $_POST['send_kkm'];
$place_tkg = $_POST['send_tkg'];
$place_kf = $_POST['send_kf'];
} else {
$place_kkm = "Anzahl je m²";
$place_tkg = "TKG (g)";
$place_kf = "KF (%)";
}
// Eingabe Parameter
// Anzahl Keimfähige Körner je m²
$saat .= "\n<input type=\"number\" name=\"send_kkm\" id=\"send_kkm\" min=\"30\" max=\"900\" placeholder=\"" . $place_kkm . "\" required>";
$saat .= "\n<label for=\"send_kkm\">Keimfähige Körner</label><br>";
// TKG in g
$saat .= "\n<input type=\"number\" name=\"send_tkg\" id=\"send_tkg\" min=\"5\" max=\"500\" placeholder=\"" . $place_tkg . "\" required>";
$saat .= "\n<label for=\"send_tkg\">Tausendkornmasse</label><br>";
// Keimfähigkeit in %
$saat .= "\n<input type=\"number\" name=\"send_kf\" id=\"send_kf\" min=\"80\" max=\"100\" placeholder=\"" . $place_kf . "\" required>";
$saat .= "\n<label for=\"send_kf\">Keimfähigkeit</label>";
$saat .= "\n</fieldset>";
// Senden
$saat .= "\n<fieldset>";
$saat .= "\n<legend>Abschicken</legend>";
$saat .= "\n<button type=\"submit\" value=\"Submit\">Berechnen</button>";
$saat .= "\n<button type=\"reset\" name=\"reset\" value=\"Reset\">Reset</button>";
$saat .= "\n</fieldset>";
// Formular schließen
$saat .= "\n</form>\n";
// Formular auswerten und Aussaatmenge berechnen
if ( isset ($_POST['send_frucht']) and isset ($_POST['send_kkm']) and isset ($_POST['send_tkg']) and isset ($_POST['send_kf']) ) {
$frucht = $_POST['send_frucht']; // Fruchtart
$kkm = $_POST['send_kkm']; // Anzahl Körner
$tkg = $_POST['send_tkg']; // TKG
$kf = $_POST['send_kf']; // Keimfähgikeit
$menge = round ( $kkm * $tkg / $kf, 0 ); // Aussaatmenge
} else { // Wenn was schief gegangen ist
$frucht = '';
$kkm = '';
$tkg = '';
$kf = '';
$menge = 1;
}
// Berechnen
for ( $j = 0; $j < count ($array); $j++ ) {
if ( $frucht == $array [$j]['Kultur'] ) {
// Keimfähige Körner
$kkm_min = $array [$j]['kkm_min'];
$kkm_max = $array [$j]['kkm_max'];
// Plausibilitätsprüfung, Abweichung 5 oder 10%
if ( $kkm < $kkm_min or $kkm > $kkm_max ) {
$kkm_text = "";
if ( $kkm < $kkm_min ) {
if ( $kkm < $kkm_min - $kkm_max * 5 / 100 )
$kkm_text .= "sehr ";
$kkm_text .= "wenig";
} elseif ( $kkm > $kkm_max ) {
if ( $kkm > $kkm_max + $kkm_max * 5 / 100 )
$kkm_text .= "sehr ";
$kkm_text .= "viel";
}
}
// Tausendkorngewicht
$tkg_min = $array [$j]['tkg_min'];
$tkg_max = $array [$j]['tkg_max'];
// Plausibilitätsprüfung, Abweichung 5 oder 10%
if ( $tkg < $tkg_min or $tkg > $tkg_max) {
$tkg_text = "";
if ( $tkg < $tkg_min) {
if ( $tkg < $tkg_min - $tkg_min * 5 / 100 )
$tkg_text .= "sehr ";
$tkg_text .= "gering";
}
elseif ( $tkg > $tkg_max) {
if ( $tkg > $tkg_max + $tkg_max * 5 / 100 )
$tkg_text .= "sehr ";
$tkg_text .= "hoch";
}
}
// Keimfähikeit
$kf_min = $array [$j]['kf'];
// Plausibilitätsprüfung
if ( $kf < $kf_min )
$kf_text = "zu gering";
// Aussaatstärke
$ast_min = $array [$j]['saat_min'];
$ast_max = $array [$j]['saat_max'];
// Plausibilitätsprüfung, Abweichung 5 oder 10%
if ( $menge < $ast_min or $menge > $ast_max ) {
$ast_text = "";
if ( $menge < $ast_min ) {
if ( $menge < $ast_min - $ast_min * 5 / 100 )
$ast_text .= "sehr ";
$ast_text .= "gering";
}
elseif ( $menge > $ast_max ) {
if ( $menge > $ast_max + $ast_max * 5 / 100 )
$ast_text .= "sehr ";
$ast_text .= "hoch";
}
}
}
}
// Formular erfolgreich verschickt
if ( isset ($_POST['send_frucht']) and isset ($_POST['send_kkm']) and isset ($_POST['send_tkg']) and isset ($_POST['send_kf']) ) {
$saat .= "\n<dl style=\"text-align: center\" id=\"ass\">";
$saat .= "\n<dt>Aussaatstärke " . $frucht . "</dt>";
$saat .= "\n<dd><strong style=\"font-size: 1.8em;\">" . $menge . " kg/ha</strong><br>(" . $kkm . " keimfähige Körner, " . $tkg . " g Tausendkorngewicht und " . $kf . " % Keimfähgikeit)</dd>";
$saat .= "\n</dl>";
// Aussaatstärke
if ( isset ($ast_text) )
$saat .= "\n<p class=\"warn\">Die <strong>Aussaatstärke</strong> für " . $frucht . " ist mit " . $menge . " kg/ha " . $ast_text . ". Üblich sollten zwischen " . $ast_min . " und " . $ast_max . " kg/ha sein.</p>";
if ( isset ($kkm_text) or isset ($tkg_text) or isset ($kf_text) or isset ($ast_text) ) {
$saat .= "<p class=\"warn\">";
// Anzahl keimfähige Körner
if ( isset ($kkm_text) )
$saat .= "Die Anzahl von " . $kkm . " <strong>keimfähigen Körnern je m²</strong> ist " . $kkm_text . " und sollte zwischen " . $kkm_min . " und " . $kkm_max . " je m² betragen! ";
// TKG
if ( isset ($tkg_text) )
$saat .= " Das <strong>TKG</strong> ist mit " . $tkg . " g " . $tkg_text . " und sollte bei " . $tkg_min . " bis " . $tkg_max . " g liegen.";
// Keimfähigkeit
if ( isset ($kf_text) )
$saat .= " Die <strong>Keimfähigkeit</strong> sollte mindestens " . $kf_min . " % betragen, sie ist mit " . $kf . " % " . $kf_text . ".";
$saat .= "</p>";
}
}
// Ausgabe
echo $saat;
}
Kalender
KW | Mo | Di | Mi | Do | Fr | Sa | So |
---|---|---|---|---|---|---|---|
18 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
19 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
20 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
22 | 29 | 30 | 31 | 1 | 2 | 3 | 4 |
KW | Mo | Di | Mi | Do | Fr | Sa | So |
---|---|---|---|---|---|---|---|
22 | 29 | 30 | 31 | 1 | 2 | 3 | 4 |
23 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
24 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
25 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 26 | 27 | 28 | 29 | 30 | 1 | 2 |
<?php //hosting
function kalender ($datum) {
// Zeitangaben
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
setlocale (LC_TIME, 'de_DE.utf8');
date_default_timezone_set ('Europe/Berlin');
$tage = date ( 't', mktime ( 0, 0, 0, date ( 'm', strtotime ($datum) ), 1 , date ('Y', strtotime ($datum) ) ) );
$start = mktime ( 0, 0, 0, date ( 'n', mktime ( 0, 0, 0, date ( 'm', strtotime ($datum) ), 1 , date ('Y', strtotime ($datum) ) ) ), 1, date ( 'Y', mktime ( 0, 0, 0, date ( 'm', strtotime ($datum) ), 1 , date ('Y', strtotime ($datum) ) ) ) );
$start_tag = date ( 'N', $start);
$ende_tag = date ( 'N', mktime ( 0, 0, 0, date ( 'n', mktime ( 0, 0, 0, date ( 'm', strtotime ($datum) ), 1 , date ('Y', strtotime ($datum) ) ) ), $tage, date ( 'Y', mktime ( 0, 0, 0, date ( 'm', strtotime ($datum) ), 1 , date ('Y', strtotime ($datum) ) ) ) ) );
// Tabelle erstellen
$kalender = "";
$kalender .= "\n<table>";
$kalender .= "\n<caption>" . strftime ( '%B %G', strtotime ($datum) ) . "</caption>";
$kalender .= "\n<thead>";
$kalender .= "\n<tr>";
$kalender .= "\n<th style=\"color: silver\">KW</th>";
$kalender .= "\n<th>Mo</th>";
$kalender .= "\n<th>Di</th>";
$kalender .= "\n<th>Mi</th>";
$kalender .= "\n<th>Do</th>";
$kalender .= "\n<th>Fr</th>";
$kalender .= "\n<th>Sa</th>";
$kalender .= "\n<th>So</th>";
$kalender .= "\n</tr>";
$kalender .= "\n</thead>";
// Inhalkt
$kalender .= "\n<tbody>";
// Start Tag ermitteln
for ( $i = 1; $i <= $tage + ( $start_tag - 1 ) + ( 7 - $ende_tag ); $i++) {
$aktuell = $i - $start_tag;
$heute = strtotime ( $aktuell . " day", $start );
// tr öffnen
if ( date ( 'N', $heute ) == 1)
$kalender .= "\n<tr>";
// Kalenderwoche
if ( date ( 'N', $heute ) == 1)
$kalender .= "\n<td data-label=\"Kalenderwoche\" style=\"color: silver\">" . date ( 'W', $heute) . "</td>";
// td öffnen
$kalender .= "\n<td";
// data-label
$kalender .= " data-label=\"" . strftime ('%d.%m.%Y (%a)', $heute) . "\"";
// heute
if ( date( 'd.m.Y' ) == date ( 'd.m.Y', $heute ) )
$kalender .= " style=\"color: white; background: slategrey\"";
$kalender .= ">";
// Kalendertage aktueller, vorheriger und nachfolgender Monat
if ( $aktuell >= 0 AND $aktuell < $tage) {
$kalender .= date ('j', $heute );
} else {
$kalender .= "<span style=\"color: slategrey\">" . date ('j', $heute ) . "</span>";
}
// td schließen
$kalender .= "</td>";
// tr schließen
if ( date ('N', $heute ) == 7 )
$kalender .= "\n</tr>";
}
$kalender .= "\n</tbody>";
$kalender .= "\n</table>";
echo $kalender;
}
kalender ( ( date ('d.m.Y', strtotime ( date ( 'd.m.Y', time() ) .'0 months') ) ) ); kalender ( ( date ('d.m.Y', strtotime ( date ( 'd.m.Y', time() ) .'1 months') ) ) );
Tierkreiszeichen
PHP Script zur Erstellung von Webseiten
➊ Der obere Teil
<?php
require_once ( $_SERVER['DOCUMENT_ROOT'] .'/style.inc.php');
css ();
headsend ();
?><!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
<head>
<title><?php if ( isset ($title) ) echo $title; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php if ( isset ($descr) ) echo "<meta name=\"description\" content=\"$descr\">\n"; ?>
<?php if ( isset ($keywo) ) echo "<meta name=\"keywords\" content=\"$keywo\">\n"; ?>
<?php if ( isset ($robot) ) echo "<meta name=\"robots\" content=\"$robot\">\n"; ?>
<style><?php echo $buffer; if ( isset ($style) ) echo $style ?></style>
</head>
<body>
<header id="top">
<!-- Seitentitel -->
<h1><a href="/">HTML, CSS und PHP Testseiten</a></h1>
</header>
<nav>
<!-- Navigation -->
<a href="/">Startseite</a>
<a href="/html-info.php">HTML</a>
<a href="/php-info.php">PHP</a>
</nav>
➋ Die Inhaltsdatei
<?php
//<head>
$title = "Tummelplatz zum Testen von Webseiten";
$descr = "Testfeld für den Einsatz von HTML, CSS und PHP zur Erstellung von Webseiten";
$keywo = "HTML, CSS, PHP, Webseiten, Testlabor";
$robot = "index, follow";
//$style = "";
require_once ( $_SERVER['DOCUMENT_ROOT'] .'/oben.inc.php');
?>
<main id="inhalt">
<h2>Tummeplatz</h2>
<p>Willkommen auf meinem Tummelplatz zum Testen von Webseiten.</p>
</main>
<aside id="extra">
<h2>Navigation</h2>
<ul>
<li><a href="/html-info.php">HTML</a></li>
<li><a href="/php-info.php">PHP</a></li>
</ul>
</aside>
<?php require_once ( $_SERVER['DOCUMENT_ROOT'] .'/unten.inc.php'); ?>
➌ Der untere Teil
<?php //lc
// Länge
if ( strlen ($title) > 15 and strlen ($title) < 55 )
$tag_title = " class=\"pos\""; else $tag_title = " class=\"neg\"";
if ( strlen ($descr) > 140 and strlen ($descr) < 160 )
$tag_descr = " class=\"pos\""; else $tag_descr = " class=\"neg\"";
// Formular
include 'formular.php';
?>
<div id="post" class="grid" style="background: #eee">
<!-- Kommentare -->
<div>
<h2>Kommentare</h2>
<p>Schreibe den ersten <a href="#feedback">Kommentar</a></p>
</div>
<!-- Formular -->
<div>
<?php form (); ?>
</div>
</div>
<footer class="flex">
<div>
<h2>Hosting</h2>
<p>Dankbar gespeichert und ausprobiert auf den Webserven von <a href="https://www.lima-city.de/">lima-city</a>.</p>
</div>
<div>
<h2>Optimierung</h2>
<ul>
<li <?php echo $tag_title; ?> title="Optimal sind etwa zwischen 15 und 55 Zeichen"><?php echo "<title>: " . strlen ($title) . " Zeichen"; ?></li>
<li <?php echo $tag_descr; ?> title="Optimal sind etwa zwischen 140 und 160 Zeichen"><?php echo "<description>: " . strlen ($descr) . " Zeichen"; ?></li>
</ul>
</div>
</footer>
<a href="#top" class="top" title="TOP"><span style="display: block; transform: rotate(270deg)">➜</span></a>
</body>
</html>
Kontakt
Poste den ersten Kommentar oder schicke einfach eine Nachricht.