Hello,
Just creates this on the fly and i am sure that this can be made a lot better...
<?php
session_start();
if($_GET['reset'] == 1){
unset($_SESSION['input']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hang Man</title>
</head>
<body>
<form action="hang.php" method="post">
Letter:
<input name="letter" type="text" size="1" maxlength="1"/>
</form>
<?php
$word = "h e l l o w o r l d";
if (!isset( $_SESSION['input'] ) ) {
$_SESSION['input'] = array();
}
$_SESSION['input'][] = $_POST['letter'];
$word = explode(" ",$word);
foreach($word as $x){
if(in_array($x, $_SESSION['input'])){
echo $x;
}else{
echo " _ ";
}
}
?>
<p><a href="?reset=1">Reset</a></p>
</body>
</html>
The only thing i could not do is split a word into an array, i had to enter the spaces manually. Any help would be handy 🙂