PHP Random Wort Ausgabe mit Auswertung
Guten Abend
Ich glaube ich brauche mal eure Hilfe.
Und zwar habe ich in der Schule die Aufgabe ein PHP Scrip zu erstellen was mir per Zufall aus vordefinierten Wörtern ( ) Anzeigt wie viele Nicht Vokale das per Zufall angezeigte Wort hat.
Aktuell habe ich es so das er mir per Random ein Wort anzeigt aber nicht wie viele nicht Vokale .
Er listet mir irgendwie alle Wörter auf
Ich glaube ich brauche mal eure Hilfe.
Und zwar habe ich in der Schule die Aufgabe ein PHP Scrip zu erstellen was mir per Zufall aus vordefinierten Wörtern (
$my_arr = ["Maus", "Automobil", "Schifffahrt", "Hund", "Katze", "Ziege", "Stanniolpapier", "Elefant", "Isopropylalkohol", "Schwimmbad"];
Aktuell habe ich es so das er mir per Random ein Wort anzeigt aber nicht wie viele nicht Vokale .
Er listet mir irgendwie alle Wörter auf
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Spielereien</title>
</head>
<body>
<h1>Keine Vokale</h1>
<?php
$my_arr = ["Maus", "Automobil", "Schifffahrt",
"Hund", "Katze", "Ziege", "Stanniolpapier",
"Elefant", "Isopropylalkohol", "Schwimmbad"];
$rand_index = array_rand($my_arr);
echo $my_arr[$rand_index];
foreach ($my_arr As $s) {
#echo "<p>Der String \"$s\" hat " .strlen($s) ." Zeichen.</p>";
$vokale = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z", "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z"];
$zaehler = 0;
for($i=0; $i < strlen($s); $i++) {
if(in_array($s[$i], $vokale)) {
$zaehler++;
}
}
echo "<p>Das Wort \"$s\" hat $zaehler Zeichen die keine Vokale sind.</p>";
}
?>
</body>
</html>
Please also mark the comments that contributed to the solution of the article
Content-ID: 6061812440
Url: https://administrator.de/forum/php-random-wort-ausgabe-mit-auswertung-6061812440.html
Printed on: January 24, 2025 at 20:01 o'clock
4 Comments
Latest comment
... und das funktioniert? Sieht auch eher wie copy & paste aus, da Du jetzt plötzlich RegEx verwendest...