Unterrichtsmaterialien Informationsverarbeitung
PHP eingebettet in HTML
Benötigtes Vorwissen
PHP wird in Webanwendungen zur Ausgabe in HTML eingebettet.
<?php
/**
* Description of Zeiten
* @author T.Smit
* @version 1.0 beta
*/
class Zeiten {
private $timestamp;
public static $MinutesPerHour=60;
public function __construct($timestamp) {
$this->timestamp = $timestamp;
}
public function getInitialTimestamp() {
return $this->timestamp;
}
public function addDaysToInitialTimestamp($daysToAdd) {
$dayToAdd = (int) $daysToAdd;
return strtotime('+' . $dayToAdd . ' days', $this->timestamp);
}
public static function addDaysToTimestamp($daysToAdd, $Timestamp) {
$dayToAdd = (int) $daysToAdd;
return strtotime('+' . $dayToAdd . ' days', $Timestamp);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Titel der Webseite</title>
<!-- weitere Kopfinformationen -->
<!-- Kommentare werden im Browser nicht angezeigt. -->
</head>
<body>
<p>Inhalt der Webseite</p>
<?php
//usage
$cZeiten=new Zeiten(time());
echo date('Y-m-d',$cZeiten->getInitialTimestamp()); //today
echo date('Y-m-d',$cZeiten->addDaysToInitialTimestamp(1)); //tomorrow
$arbitraryTimestamp=time();
echo date('Y-m-d',$Zeiten::addDaysToTimestamp(1,$arbitraryTimestamp)); //little later
?>
</body>
</html>
Lizenziert unter Creative Commons Attribution Share Alike License 4.0