Location: PHPKode > scripts > CodeBreak - Hidden Morse Code > codebreak-hidden-morse-code/dictionary/install.php
<?php
include("../functions.inc.php");
database_connect();

if (!$option_database) die('I cannot connect to the database because: ' . mysql_error());

// CREATE A MORSE CODE PATTERN FOR EACH WORD IN WORDS.TXT AND INSERT INTO DICTIONARY TABLE
$handle = fopen("words.txt", "r");
while (!feof($handle)) {
    $words = trim(fgets($handle));
    if (strlen($words) <= 6) {
        for ($cn = 0; $cn < strlen($words); $cn++) {
            $wc = substr(strtoupper($words), $cn, 1);  // process one working character at a time
            switch ($wc) {
            case "0":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "1":
                $code_upper .= "-";
                $code_lower .= ".";
                break;
            case "2":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "3":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "4":
                $code_upper .= "..";
                $code_lower .= ".";
                break;
            case "5":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "6":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "7":
                $code_upper .= "-";
                $code_lower .= ".";
                break;
            case "8":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "9":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "A":
                $code_upper .= "-";
                $code_lower .= "..";
                break;
            case "B":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "C":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "D":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "E":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "F":
                $code_upper .= "-";
                $code_lower .= ".";
                break;
            case "G":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "H":
                $code_upper .= "..";
                $code_lower .= "..";
                break;
            case "I":
                $code_upper .= ".";
                $code_lower .= ".";
                break;
            case "J":
                $code_upper .= ".";
                $code_lower .= "-";
                break;
            case "K":
                $code_upper .= "..";
                $code_lower .= "..";
                break;
            case "L":
                $code_upper .= ".";
                $code_lower .= "-";
                break;
            case "M":
                $code_upper .= "-";
                $code_lower .= "...";
                break;
            case "N":
                $code_upper .= "-";
                $code_lower .= "..";
                break;
            case "O":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "P":
                $code_upper .= "-";
                $code_lower .= ".";
                break;
            case "Q":
                $code_upper .= $wc;
                $code_lower .= $wc;
                break;
            case "R":
                $code_upper .= "-";
                $code_lower .= "..";
                break;
            case "S":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            case "T":
                $code_upper .= "-";
                $code_lower .= ".";
                break;
            case "U":
                $code_upper .= "..";
                $code_lower .= "-";
                break;
            case "V":
                $code_upper .= "..";
                $code_lower .= "-";
                break;
            case "W":
                $code_upper .= "...";
                $code_lower .= "-";
                break;
            case "X":
                $code_upper .= "..";
                $code_lower .= "..";
                break;
            case "Y":
                $code_upper .= "..";
                $code_lower .= ".";
                break;
            case "Z":
                $code_upper .= "-";
                $code_lower .= "-";
                break;
            default:
                $code_upper .= $wc;
                $code_lower .= $wc;
            }
        }
        mysql_query("INSERT INTO dictionary VALUES ('" . $words . "','" . addslashes($code_upper) . "','" . addslashes($code_lower) . "')");
        unset($code_upper);
        unset($code_lower);
    }
}
fclose($handle);

echo("<p><b>Database update completed. You may delete the \"dictionary\" folder now if you wish.</b></p>\n");
?>
Return current item: CodeBreak - Hidden Morse Code