XAMPP – Teil2
Transcrição
XAMPP – Teil2
XAMPP – Teil2 PHP PGP X/04 PHP war mal … ! ! ! ! ! Personal Home Page Jetzt nur noch: PHP Hypertext Preprocessor PGP X/04 Ressourcen ! ! Tutorials: http://www.phpwelt.de/tutorials/tarchiv.php XAMPP, neueste Versionen mit PHP5.x: http://www.apachefriends.org/de/xampp-windows.html (win) http://www.apachefriends.org/de/xampp-linux.html (lin) http://www.webedition.de/deutsch/home/mamp.html (mac) ! PHP benötigt einen Webserver (z.B. Apache), der den PHP-Output über HTML darstellt. PGP X/04 PHP-Beispiele ! ! Ein erstes PHP-Programm – Achtung: über einen Webserver aufrufen!: <?PHP PHPINFO(); ?> Zeigt haufenweise Informationen an. PGP X/04 Variablen und ihre Belegung ! ! ! ! ! ! Der „echo“-Befehl gibt etwas aus! $i=6; echo isset($i); unset($i); echo isset($i); " True = 1, false = „nichts!“ PGP X/04 Stringverkettung ! $Vorname=„Gerd"; $Nachname=„Müller"; $Name=$Vorname." ".$Nachname; echo $Name; ! Geliefert wird der komplette Name ! ! ! PGP X/04 Rechnen ! Wer C oder C++ kennt, ist leicht im Vorteil: $i++ - Wert von i wird um 1 erhöht ! $a=$+$c ! PGP X/04 - funktioniert einfach so. Eine Schleife … ! ! ! ! ! ! ! ! $x=1; echo „<table border='1'>“; - Achtung: einfache Anführungszeichen statt doppelte wie in HTML!!! while ($x <= 10) { echo "<TR><td> x </td><td> $x </td></tr>"; $x++; }; echo"</table>„; PGP X/04 Arrays ! ! ! ! $farbe = array(„Kreuz“, „Herz“, „Pik“, „Karo“); In eine Schleife (wie letzte Folie einfügen): echo "<TR><td> x </td><td> $x </td><td>$farbe[$x]</td></tr>"; Also: der Index des Arrays beginnt bei 0! PGP X/04 Datenübergabe - Sendescript ! ! ! ! ! ! ! ! <HTML> <BODY> <FORM ACTION="script.php" METHOD="post"> Name: <INPUT TYPE="text" NAME="Name"> Email: <INPUT TYPE="text" NAME="Email"> <INPUT TYPE="submit" VALUE="abschicken"> </FORM> </BODY> </HTML> PGP X/04 Datenübergabe - Empfänger ! ! ! ! ! ! ! ! <HTML> <BODY> <? echo "Ihr Name ist " . $Name . "<br>"; echo "Und Ihre email-Adresse ist ".$Email."<br>"; ?> </BODY> </HTML> PGP X/04 Speichern in Dateien – PHP-Teil ! ! ! ! ! ! ! ! ! ! ! <? $dateiname = "zaehler.txt"; $zaehler = 0; if(file_exists($dateiname)) { $datei = fopen($dateiname, "r"); if($datei) { $zaehler = fgets($datei,255); fclose($datei); } PGP X/04 } $zaehler++; $datei = fopen($dateiname, "w"); if($datei) { fputs($datei,$zaehler); fclose($datei); } ?> Speichern – und nun der HTML-Teil ! <html> <head> <title>Counter</title> <meta name="author" content="Administrator"> <meta name="generator" content="Ulli Meybohms HTML EDITOR"> </head> <body> <? echo "Sie sind der Besucher Nummer $zaehler! <br>\n" ?> </body> </html> ! (Alles hintereinander in 1 Datei speichern – ein Besucherzähler!) ! ! ! ! ! ! ! ! ! PGP X/04 Und ….. ! … viel mehr Beispiele gibt‘s im Netz. PGP X/04