<?php
$katacheck 
'';
$hiracheck 'checked="checked"';
if (isset(
$_GET['type'])) {
    if (
$_GET['type'] == 'hiragana') {
      
$hiracheck 'checked="checked"';
  } else {
      
$katacheck 'checked="checked"';
    
$hiracheck '';
  }
} else {
  
$hiracheck 'checked="checked"';
}

$romaji = Array(
                  
'a',  'i',   'u',   'e',  'o',
                  
'ka''ki',  'ku',  'ke''ko',
                  
'ga''gi',  'gu',  'ge''go',
                  
'sa''shi''su',  'se''so',
                  
'za''ji''zu',  'ze''zo',
                  
'ta''chi''tsu''te''to',
                  
'da''di''du''de''do',
                  
'na''ni',  'nu',  'ne''no',
                  
'ha''hi',  'fu',  'he''ho',
                  
'ba''bi',  'bu',  'be''bo',
                  
'pa''pi',  'pu',  'pe''po',
                  
'ma''mi',  'mu',  'me''mo',
                  
'ya',        'yu',  'yo',
                  
'ra''ri',  'ru',  're''ro',
                  
'wa',                     'wo',
                  
'n'
                  
);

$hiragana_kana = Array(
                  
'あ''い',  'う',   'え',  'お',
                  
'か''き',  'く',  'け''こ',
                  
'が''ぎ',  'ぐ',  'げ''ご',
                  
'さ''し',  'す',  'せ''そ',
                  
'ざ''じ',  'ず',  'ぜ''ぞ',
                  
'た''ち',  'つ''て''と',
                  
'だ''ぢ',  'づ',  'で''ど',
                  
'な''に',  'ぬ',  'ね''の',
                  
'は''ひ',  'ふ',  'へ''ほ',
                  
'ば''び',  'ぶ',  'べ''ぼ',
                  
'ぱ''ぴ',  'ぷ',  'ぺ''ぽ',
                  
'ま''み',  'む',  'め''も',
                  
'や',        'ゆ',  'よ',
                  
'ら''り',  'る',  'れ''ろ',
                  
'わ',                     'を',
                  
'ん'
                  
);

$katakana_kana = Array(
                  
'ア''イ',  'ウ',  'エ',  'オ',
                  
'カ''キ',  'ク',  'ケ''コ',
                  
'ガ''ギ',  'グ',  'ゲ''ゴ',
                  
'サ''シ',  'ス',  'セ''ソ',
                  
'ザ''ジ',  'ズ',  'ゼ''ゾ',
                  
'タ''チ',  'ト',   'テ','ト',
                  
'ダ''ヂ',  'ヅ',  'デ''ド',
                  
'ナ''ニ',  'ヌ',  'ネ''ノ',
                  
'ハ''ヒ',  'フ',  'ヘ''ホ',
                  
'バ''ビ',  'ブ',  'ベ''ボ',
                  
'パ''ピ',  'プ',  'ペ''ポ',
                  
'マ''ミ',  'ム',  'メ''モ',
                  
'ヤ',          'ユ',  'ヨ',
                  
'ラ''リ',  'ル',  'レ''ロ',
                  
'ワ',                   'ヲ',
                  
'ン'
                  
);                  
                  

if (isset(
$_GET['characters'])) {
  if (
$_GET['characters'] > count($romaji)) {
    
$characters count($romaji);
  } else {
    
$characters $_GET['characters'];
  }
} else {                  
  
$characters 10;
}
$random_kana = Array();
$random_romaji_list '';

if (isset(
$_GET['action']) && $_GET['action'] == 'Facit') {
    
$romajivalue split(';'$_GET['romajivalue']);
  
$random_romaji_list $_GET['romajivalue'];
    if (
$katacheck == '') {
    for (
$i=0;$i<count($romajivalue);$i++) {
      
$key array_search($romajivalue[$i], $romaji);
      
$random_kana[$i] = $hiragana_kana[$key];
    }
    } else {
    for (
$i=0;$i<count($romajivalue);$i++) {
      
$key array_search($romajivalue[$i], $romaji);
      
$random_kana[$i] = $katakana_kana[$key];
    }
    }
} else {
  for (
$i=0;$i<$characters;$i++) {
    
$new $romaji[rand(0count($romaji)-1)];
    if (!
in_array($new$random_kana)) {
      
$random_kana[$i] = $new;
    } else {
      
$i--;
    }
  }
  
$romajivalue $random_kana;
  for (
$i=0;$i<count($romajivalue);$i++) {
    
$random_romaji_list .=  $romajivalue[$i];
    if (
$i != count($romajivalue)-1) {
      
$random_romaji_list .=  ';';
    }
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <META http-equiv="Content-type" content="text/html; charset=UTF-8">
    <title></title>
  <style type="text/css" media="screen">
  body {
    text-align:center;
  }
  fieldset {
    border: none;
    padding: 0px;
    margin: 0px;
    text-align: center;
  }
  
  input.button {
    font-size: 30px;
  }
  
  div.letters {
    padding-bottom: 40px;
    text-align: center;
  }
  
  ul {
    text-align:center;
    list-style: none;
    margin: 0;
    padding: 0;
    margin-left: auto;
    margin-right: auto;
  }
  
  ul li {
    margin: 0;
    padding: 0;
    display: inline;
  }

  ul li span {
    width: 70px;
    background: #EFEFEF;
    margin: 2px;
    padding: 6px;
    font-size: 39px;
      font-family: Monospace;
  }

  ul li span.kana {
    font-size: 50px;
    padding: 5px;
      font-family: MS PGothic;
  }
  
  div#center {
    width: 100%;
    padding-top: 200px;
  }
  div#content {
    margin-left: auto;
    margin-right: auto;
    width: 750px;
    text-align:left;
  }
  </style>
<script type="text/javascript">
function giveFocus() {
   document.myform.newbutton.focus();


</script>
</head>

<body onload="giveFocus();">
<div id="content">
  <div id="center">
    <form name="myform" action="" method="get">
      <fieldset>
        <input type="hidden" name="romajivalue" value="<?php echo $random_romaji_list?>" />
        <div class="letters">
        <ul>
        <?php
        
for ($i=0;$i<count($random_kana);$i++) {
          echo 
'<li><span class="kana">'.$random_kana[$i].'</span></li>'."\n";
        }
        
?>
        </ul>
        </div>
        <?php
        
if (isset($_GET['action']) && $_GET['action'] == 'Facit') {
          echo 
'
        <div class="letters">
        <ul>
          
          '
;
          for (
$i=0;$i<count($romajivalue);$i++) {
            echo 
'<li><span>'.$romajivalue[$i].'</span></li>'."\n";
          }
          echo 
'
        </ul>
        </div>
          
          '
;
        }
        
?>
        <div id="body">
        <input class="button" type="submit" value="New" tabindex="1" name="action">
        <input class="button" type="submit" value="Facit" tabindex="2" name="action">

        <br/><br/>
        <input type="radio" name="type" value="hiragana" <?php echo $hiracheck?> /> Hiragana 
        <input type="radio" name="type" value="katakana" <?php echo $katacheck?> /> Katakana
        <br/><br/>
        Characters: <input name="characters" value="<?php echo $characters?>" />
        </div>
      </fieldset>
    </form>
  </div>
</div>
</body>
</html>