Files
creator/templates/Referenz/MiniGuide.md
2026-06-06 00:14:43 +02:00

395 lines
13 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
```
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>PHP Mini-Guide</title>
<style>
@page {
size: A4;
margin: 18mm 18mm 16mm 18mm;
@bottom-center {
content: counter(page) " / " counter(pages);
font-family: -apple-system, "Segoe UI", sans-serif;
font-size: 8pt;
color: #888;
}
@bottom-right {
content: "PHP Mini-Guide";
font-family: -apple-system, "Segoe UI", sans-serif;
font-size: 8pt;
color: #888;
}
}
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--php: #777BB4;
--php-dark: #4F5B93;
--php-darker: #2C3E66;
--ink: #1a1a1a;
--muted: #5a6470;
--line: #d8dde3;
--bg-soft: #f5f5fb;
--code-bg: #1e2a3a;
--code-fg: #e6e6e6;
--plus: #2c8a3e;
--minus: #c0392b;
}
/* Darkmode — die App setzt data-theme="dark" auf <html>; Druck/PDF bleibt hell */
@media screen {
html[data-theme="dark"] {
--ink: #e6e8ee;
--muted: #9aa3b2;
--line: #2c3038;
--bg-soft: #23262e;
}
html[data-theme="dark"] body { background: #15171c; }
html[data-theme="dark"] .callout { background: var(--bg-soft); }
}
html, body {
font-family: Charter, "Source Serif Pro", Georgia, serif;
color: var(--ink);
font-size: 10.5pt;
line-height: 1.55;
}
/* ===== HEAD ===== */
.head {
display: table;
width: 100%;
border-bottom: 2pt solid var(--ink);
padding-bottom: 4mm;
margin-bottom: 5mm;
}
.head-logo, .head-title, .head-meta {
display: table-cell;
vertical-align: middle;
}
.head-logo {
width: 20mm;
padding-right: 5mm;
}
.head-logo-box {
width: 16mm; height: 16mm;
background: linear-gradient(135deg, var(--php) 0%, var(--php-dark) 100%);
border-radius: 4mm;
display: flex; align-items: center; justify-content: center;
font-family: -apple-system, sans-serif;
font-size: 11pt; font-weight: 800;
color: white;
}
.head-title h1 {
font-family: -apple-system, sans-serif;
font-size: 20pt;
font-weight: 800;
color: var(--php-dark);
letter-spacing: -0.5pt;
line-height: 1.1;
}
.head-title h1 .accent { color: var(--php); }
.head-title .subtitle {
font-family: -apple-system, sans-serif;
font-size: 10pt;
color: var(--muted);
margin-top: 1mm;
}
.head-meta {
width: 35mm;
text-align: right;
font-family: -apple-system, sans-serif;
}
.head-meta .badge {
display: inline-block;
background: var(--ink);
color: white;
padding: 1.2mm 3mm;
border-radius: 1.5mm;
font-size: 8.5pt;
font-weight: 700;
}
.head-meta .time {
display: block;
font-size: 7.5pt;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 1pt;
margin-top: 1mm;
}
/* ===== GAP-OPENER ===== */
.gap {
background: var(--bg-soft);
border-left: 3pt solid var(--php);
padding: 3.5mm 5mm;
margin: 0 0 6mm 0;
font-style: italic;
font-size: 10.5pt;
}
.gap > b:first-child {
font-style: normal;
color: var(--php-dark);
font-family: -apple-system, sans-serif;
text-transform: uppercase;
font-size: 8pt;
letter-spacing: 1pt;
display: block;
margin-bottom: 1.5mm;
}
/* ===== SECTIONS ===== */
h2 {
font-family: -apple-system, sans-serif;
font-size: 13pt;
font-weight: 700;
color: var(--php-dark);
margin: 6mm 0 2.5mm 0;
page-break-after: avoid;
}
h3 {
font-family: -apple-system, sans-serif;
font-size: 10.5pt;
font-weight: 700;
color: var(--ink);
margin: 4mm 0 1.5mm 0;
page-break-after: avoid;
}
p {
margin-bottom: 2.5mm;
text-align: justify;
hyphens: auto;
}
p b { color: var(--php-dark); }
ul, ol { margin: 1.5mm 0 3mm 6mm; }
li { margin-bottom: 1mm; }
/* ===== CODE ===== */
pre {
background: var(--code-bg);
color: var(--code-fg);
font-family: "SF Mono", Consolas, monospace;
font-size: 8.5pt;
line-height: 1.5;
padding: 3mm 4mm;
border-radius: 2mm;
margin: 2.5mm 0 3.5mm 0;
white-space: pre;
overflow: hidden;
page-break-inside: avoid;
}
.c { color: #6b8aae; font-style: italic; }
.k { color: #ff79c6; }
.s { color: #f1c40f; }
.f { color: #50fa7b; }
.t { color: #8be9fd; }
.v { color: #ffb86c; }
code.inline {
font-family: "SF Mono", Consolas, monospace;
font-size: 9pt;
background: var(--bg-soft);
padding: 0.3mm 1.5mm;
border-radius: 1mm;
color: var(--php-dark);
}
/* ===== CALLOUT ===== */
.callout {
border-radius: 2mm;
padding: 2.5mm 4mm;
margin: 3mm 0;
font-size: 10pt;
page-break-inside: avoid;
display: grid;
grid-template-columns: 6mm 1fr;
gap: 3mm;
}
.callout-icon {
font-family: -apple-system, sans-serif;
font-weight: 800;
font-size: 14pt;
line-height: 1;
text-align: center;
}
.callout-body > b:first-child {
font-family: -apple-system, sans-serif;
text-transform: uppercase;
font-size: 8pt;
letter-spacing: 1pt;
display: block;
margin-bottom: 1mm;
}
.callout.tip { background: #e8f4ea; border-left: 3pt solid var(--plus); }
.callout.tip .callout-icon, .callout.tip .callout-body > b:first-child { color: var(--plus); }
.callout.warn { background: #fdecea; border-left: 3pt solid var(--minus); }
.callout.warn .callout-icon, .callout.warn .callout-body > b:first-child { color: var(--minus); }
.callout.note { background: var(--bg-soft); border-left: 3pt solid var(--php); }
.callout.note .callout-icon, .callout.note .callout-body > b:first-child { color: var(--php-dark); }
</style>
</head>
<body>
<!-- ===== HEAD ===== -->
<header class="head">
<div class="head-logo"><div class="head-logo-box">php</div></div>
<div class="head-title">
<h1><span class="accent">PHP</span> in 15 Minuten</h1>
<div class="subtitle">Dein erstes PHP-Programm Schritt für Schritt</div>
</div>
<div class="head-meta">
<span class="badge">Mini-Guide</span>
<span class="time">15 Min · von Null</span>
</div>
</header>
<!-- ===== GAP-OPENER ===== -->
<div class="gap">
<b>Frage zum Einstieg</b>
PHP läuft hinter rund drei Viertel aller Webseiten inklusive WordPress, Wikipedia und Facebook. Aber wie sieht PHP-Code überhaupt aus, und wie startet man? In 15 Minuten kannst du dein erstes Programm schreiben.
</div>
<!-- ===== SEKTION 1 ===== -->
<h2>PHP starten</h2>
<p>PHP ist eine Programmiersprache, die auf deinem Computer oder einem Webserver läuft. Im Gegensatz zu HTML oder CSS wird PHP nicht im Browser angezeigt es <i>erzeugt</i> Ausgaben (zum Beispiel HTML), die dann ausgeliefert werden.</p>
<p>Um anzufangen, brauchst du PHP auf deinem Computer. Auf Mac: <code class="inline">brew install php</code>. Auf Ubuntu: <code class="inline">apt install php8.4-cli</code>. Auf Windows: am einfachsten WSL2 mit Ubuntu darin nutzen.</p>
<p>PHP-Code lebt in Dateien mit der Endung <code class="inline">.php</code>. Lege eine Datei <code class="inline">hallo.php</code> an mit diesem Inhalt:</p>
<pre><span class="t">&lt;?php</span>
<span class="k">echo</span> <span class="s">"Hallo Welt!"</span>;</pre>
<p>Die erste Zeile <code class="inline">&lt;?php</code> sagt PHP: "ab hier kommt mein Code". Das Wort <code class="inline">echo</code> heißt: "gib das aus, was danach kommt". Strings (also Text) stehen in Anführungszeichen. Jede Anweisung endet mit einem Semikolon.</p>
<p>Im Terminal ausführen mit:</p>
<pre>php hallo.php</pre>
<p>Du siehst "Hallo Welt!" dein erstes PHP-Programm läuft.</p>
<!-- ===== SEKTION 2 ===== -->
<h2>Variablen</h2>
<p>Eine <b>Variable</b> ist ein benannter Platz, an dem du einen Wert speicherst. In PHP beginnen Variablen immer mit einem Dollar-Zeichen <code class="inline">$</code>. Das macht sie im Code sofort erkennbar:</p>
<pre><span class="t">&lt;?php</span>
<span class="v">$name</span> = <span class="s">"Marek"</span>;
<span class="v">$alter</span> = <span class="s">34</span>;
<span class="v">$istAktiv</span> = <span class="k">true</span>;
<span class="k">echo</span> <span class="v">$name</span>;</pre>
<p>Variablen können verschiedene Arten von Werten enthalten. Die drei wichtigsten:</p>
<ul>
<li><b>Strings</b> Text in Anführungszeichen, z.B. <code class="inline">"Hallo"</code></li>
<li><b>Zahlen</b> ganze Zahlen (<code class="inline">42</code>) oder Kommazahlen (<code class="inline">3.14</code>)</li>
<li><b>Wahrheitswerte</b> <code class="inline">true</code> (wahr) oder <code class="inline">false</code> (falsch)</li>
</ul>
<p>Mit dem Punkt verbindest du Strings:</p>
<pre><span class="v">$gruss</span> = <span class="s">"Hallo, "</span> . <span class="v">$name</span> . <span class="s">"!"</span>;
<span class="k">echo</span> <span class="v">$gruss</span>; <span class="c">// Hallo, Marek!</span></pre>
<!-- ===== SEKTION 3 ===== -->
<h2>Bedingungen</h2>
<p>Programme müssen oft entscheiden: "wenn X zutrifft, mach Y, sonst Z". Dafür gibt es <code class="inline">if</code> und <code class="inline">else</code>:</p>
<pre><span class="v">$alter</span> = <span class="s">17</span>;
<span class="k">if</span> (<span class="v">$alter</span> &gt;= <span class="s">18</span>) {
<span class="k">echo</span> <span class="s">"Du bist erwachsen."</span>;
} <span class="k">else</span> {
<span class="k">echo</span> <span class="s">"Du bist noch minderjährig."</span>;
}</pre>
<p>Die Klammer hinter <code class="inline">if</code> enthält die Bedingung. Die geschweiften Klammern <code class="inline">{ }</code> umschließen den Code, der ausgeführt wird, wenn die Bedingung wahr ist. <code class="inline">else</code> ist der Block, wenn sie falsch ist.</p>
<p>Wichtige Vergleichs-Operatoren:</p>
<ul>
<li><code class="inline">==</code> gleich</li>
<li><code class="inline">!=</code> ungleich</li>
<li><code class="inline">&lt;</code>, <code class="inline">&gt;</code> kleiner, größer</li>
<li><code class="inline">&lt;=</code>, <code class="inline">&gt;=</code> kleiner-gleich, größer-gleich</li>
</ul>
<div class="callout note">
<div class="callout-icon">i</div>
<div class="callout-body">
<b>Ein Gleichheitszeichen reicht nicht</b>
Zum Zuweisen nutzt du <code class="inline">=</code> (ein Gleichheitszeichen). Zum Vergleichen brauchst du <code class="inline">==</code> (zwei). Das ist eine häufige Verwechslung bei Anfängern.
</div>
</div>
<!-- ===== SEKTION 4 ===== -->
<h2>Listen und Schleifen</h2>
<p>Mehrere Werte fasst du in einer <b>Liste</b> zusammen. In PHP heißen Listen <code class="inline">array</code>:</p>
<pre><span class="v">$obst</span> = [<span class="s">"Apfel"</span>, <span class="s">"Birne"</span>, <span class="s">"Kirsche"</span>];</pre>
<p>Über jede Liste kannst du mit <code class="inline">foreach</code> Schritt für Schritt gehen:</p>
<pre><span class="k">foreach</span> (<span class="v">$obst</span> <span class="k">as</span> <span class="v">$frucht</span>) {
<span class="k">echo</span> <span class="v">$frucht</span> . <span class="s">"\n"</span>;
}</pre>
<p>Das gibt "Apfel", "Birne", "Kirsche" untereinander aus. Das <code class="inline">\n</code> ist ein Zeilenumbruch. Die Variable <code class="inline">$frucht</code> bekommt bei jedem Durchlauf den nächsten Wert aus der Liste.</p>
<p>Listen müssen nicht aus Strings bestehen. Zahlen gehen genauso:</p>
<pre><span class="v">$zahlen</span> = [<span class="s">10</span>, <span class="s">20</span>, <span class="s">30</span>];
<span class="v">$summe</span> = <span class="s">0</span>;
<span class="k">foreach</span> (<span class="v">$zahlen</span> <span class="k">as</span> <span class="v">$zahl</span>) {
<span class="v">$summe</span> = <span class="v">$summe</span> + <span class="v">$zahl</span>;
}
<span class="k">echo</span> <span class="v">$summe</span>; <span class="c">// 60</span></pre>
<!-- ===== SEKTION 5 ===== -->
<h2>Funktionen</h2>
<p>Wenn du denselben Code mehrfach brauchst, packst du ihn in eine <b>Funktion</b>. Du gibst der Funktion einen Namen und kannst sie dann beliebig oft aufrufen:</p>
<pre><span class="k">function</span> <span class="f">begruessen</span>(<span class="v">$name</span>) {
<span class="k">echo</span> <span class="s">"Hallo, "</span> . <span class="v">$name</span> . <span class="s">"!\n"</span>;
}
<span class="f">begruessen</span>(<span class="s">"Marek"</span>);
<span class="f">begruessen</span>(<span class="s">"Anna"</span>);
<span class="f">begruessen</span>(<span class="s">"Tom"</span>);</pre>
<p>Die Funktion <code class="inline">begruessen</code> nimmt einen <b>Parameter</b> entgegen (<code class="inline">$name</code>). Beim Aufruf übergibst du den konkreten Wert in den Klammern.</p>
<p>Funktionen können auch Werte <b>zurückgeben</b>. Dafür gibt es <code class="inline">return</code>:</p>
<pre><span class="k">function</span> <span class="f">addiere</span>(<span class="v">$a</span>, <span class="v">$b</span>) {
<span class="k">return</span> <span class="v">$a</span> + <span class="v">$b</span>;
}
<span class="v">$ergebnis</span> = <span class="f">addiere</span>(<span class="s">3</span>, <span class="s">5</span>);
<span class="k">echo</span> <span class="v">$ergebnis</span>; <span class="c">// 8</span></pre>
<p>Die Funktion macht ihre Berechnung und liefert das Ergebnis zurück. Du fängst es in einer Variable auf und kannst damit weiterarbeiten.</p>
<div class="callout tip">
<div class="callout-icon">✓</div>
<div class="callout-body">
<b>Übung macht den Meister</b>
Schreibe jetzt selbst ein kleines PHP-Programm. Zum Beispiel: eine Liste deiner Lieblings-Filme, die mit <code class="inline">foreach</code> ausgegeben werden. Oder eine Funktion, die das Doppelte einer Zahl zurückgibt. Praktisch ausprobieren ist der schnellste Weg, PHP zu lernen.
</div>
</div>
</body>
</html>
```