hangman.php in chapter 8...
in the chapter 8 of the php4 book, there is a example named hangamn.php that explains the usage of query string for permanent data. In my opinion, there is an error in this example, because the variable $letters is not defined. I tried to do this example changing to italian language the name and value of variables (i'm italan..eheh:-)), but the result is the same: when I load hangamn.php and select a letter, the page failure to reload.
Is the example tht is wrong or is my code wrong? Can you help me?
This is my code:
<html>
<head>
<title>Documento senza titolo</title>
</head>
<body>
<?php
//impiccato.php
$alfabeto = array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$parole = array ("GIOVANNI", "SBARBARE", "CANZONE", "PENZOLARE", "SPLINTERCELL");
$errori = 0;
if (!isset($numeroParola)) {
$numeroParola = rand(1, count($parole)) -1;
}
echo "<H1>";
$parolaSingola = $parole[$numeroParola];
$fine = 1;
for ($counter = 0; $counter < strlen($parolaSingola); $counter++) {
if (ereg($parolaSingola[$counter], $lettere)) {
echo $parolaSingola[$counter];
} else {
echo "_";
$fine = 0;
}
}
echo "</H1>";
if ($fine) {
echo "<br><br> congratulzioni..hai vinto <br><br>";
echo "<br><br> <A HREF = $PHP_SELF>gioca ancora</A>";
} else {
foreach ($alfabeto as $indice) {
if (ereg($indice, $lettere)) {
if (ereg($indice, $parole[$numeroParola])) {
$collegamento .= "<b> $indice </b>";
} else {
$collegamento .= "$indice";
$errori++;
}
} else {
$collegamento .= "<A HREF=\"$PHP_SELF?lettere=$lettere$indice&numeroPar ola=$numeroParola\">$indice</A>";
}
} if ($errori == 12) {
echo "<br>IMPICCATO!!<br><br>";
echo "la parola da indovinare era \"$parolaSingola\"<br><br>";
echo "<A HREF = $PHP_SELF>rigioca</A>";
} else {
echo "tentativi rimanenti " . (12 - $errori) . "<br>";
echo "<br>seleziona una lettera. <br><br>";
echo $collegamento;
}
}
?>
</body>
</html>
|