<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Saarland Brewery Quiz</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>

<?php

$brewers=array('Großwald Brauerei','Homburger Brauhaus',
 'Karlsberg Brauerei','Ponter Hausbrauerei',
 'Saarfürst Merziger Brauhaus','Mettlacher Abtei-Bräu',
 'Körpricher Landbräu','Brauerei G.A. Bruch',
 'Neufang Brauerei','Zum Stiefel');

$form_top="<form action=\"$_SERVER[PHP_SELF]\" method=\"get\"><p>\n";
$form_submit='<input type="submit" value="I try!"/>'."\n";
$form_end='</p></form>';

function build_form($answer,$comment) {
  print "<div>Guess the name of a brewery in Saarland!</div>\n";
  print $GLOBALS['form_top'];
  print "<input type=\"text\" name=\"guess\" value=\"$answer\"/>";
  print $GLOBALS['form_submit'];
  print $GLOBALS['form_end'];
  print $comment;
}

function process_form($answer,$brewers) {
  $r[]=$answer;
  foreach($brewers as $brew) {
    if($answer == "$brew") {
      $r[]='<div>Congratulations! This is correct!</div>';
      return $r;
    }
  }
  foreach($brewers as $brew) {
    if(levenshtein($answer,$brew)<strlen($brew)/2) {
      $r[]='<div>This is almost correct, try again!</div>';
      return $r;
    }
  }
  $r[]='<div>This is a bad answer, try again!</div>';
  return $r;
}

if($_GET['guess']) {
  $from_form=process_form($_GET['guess'],$brewers);
}
build_form($from_form[0],$from_form[1]) ;

?>


<p>
<a href="http://validator.w3.org/check?uri=referer"><img
    style="border: 0pt"
    src="/valid-xhtml10.png"
    alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>





Valid XHTML 1.0!