Choose a file to view:
index.php  word.php  functions.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" >
<script type="text/javascript" src="periodic.js"></script>
<link rel="stylesheet" type="text/css" href="/style.css">
<style type='text/css'>
table { border-style: solid; border-width: 0 0 1px 1px; border-spacing: 0; margin: 7px; font-family: serif; }
td { border-style: solid; border-width: 1px 1px 0 0; padding: 5px; }
</style>
<title>Element Speller</title>
</head>
<body onload='init()'>
<h2>Periodic Table Speller</h2>
<p>Enter a word to see if it can be spelled using only element abbreviations from the Periodic Table.</p>
<?php
$input 
$_GET['word'] ?? NULL;
$length $_GET['length'] ?? 1;
$num $_GET['num'] ?? FALSE;
$name $_GET['name'] ?? FALSE;
$mass $_GET['mass'] ?? FALSE;
$suggest $_GET['suggest'] ?? FALSE;

$r1 $r2 '';
if(
$length == 2)
    
$r2 "checked";
else
    
$r1 "checked";
$first = !isset($input);
?>
<form action="index.php" method="get">
<p><input type="text" name="word" id="word">
<input type="submit" value="Submit"><br>
<p>Image: <input id="chkNum" type="checkbox" name="num" value="1" <?php echo $num || $first 'checked' ''?>><label for="chkNum">Show number</label>
<input id="chkName" type="checkbox" name="name" value="1" <?php echo $name || $first 'checked' ''?>><label for="chkName">Show name</label>
<input id="chkMass" type="checkbox" name="mass" value="1" <?php echo $mass || $first 'checked' ''?>><label for="chkMass">Show mass</label></p>
<p>Use more: <input id="btnOne" name="length" type="radio" value="1" <?=$r1?>><label for="btnOne">One-letter symbols</label> <input id="btnTwo" name="length" type="radio" value="2" <?=$r2?>><label for="btnTwo">Two-letter symbols</label>
</p>
<input id="suggest" type="hidden" name="suggest" value="<?php echo $suggest ?: '0'?>"></form>
<?PHP
require 'functions.php';
$solution '';
if(
$input != null) {
    
$db db_connect();
    
$e elements($dbtrue);
    
$solvable true;
    echo 
"<h1 style='margin-top: 1em'>";
    
$words preg_replace('/[\W]+/'''explode(' '$input));
    
$size = ($length == "2");
    foreach( 
$words as $word ) {
        
$sub periodic($word$e$size);
        if( !
$sub )
            
$solvable false;
        
$solution $solution." ".$sub;
    }
    if( 
$solvable ) {
        
save($dbstrtolower($solution));
        echo 
trim$solution );
        if(
$name && $num && $mass && !$size// pretty image URL for default settings
            
$img urlencode(trim($solution)).'.png';
        else
            
$img "word.php?word=".urlencode(trim($solution))."&amp;showname=".$name."&amp;shownum=".$num."&amp;showmass=".$mass."&amp;size=$size";
        echo 
"<br><br><br><img src='$img' alt='Successfully spelled with element symbols'>";
        
$spelled countspelled($dbstrtolower($solution));
        echo 
"</h1><p><br>This phrase has been spelled $spelled time".($spelled == "" "s").'</p>';
    } else {
// HIDDEN
        
if(in_array(strtolower($input), array('aradia''tavros''sollux''karkat''nepeta''kanaya''terezi''vriska''equius''gamzee''eridan''feferi''andrew hussie''john egbert''rose lalonde''dave strider''jade harley''jane crocker''roxy lalonde''dirk strider''jake english''homestuck''prospit''derse''zoosmell pooplord')))
            echo 
"<img src='tryagain.gif'></h1>";
        else if(
strtolower($input == 'inconceivable'))
            echo 
"<img src='/img/inconceivable.jpg'><br><br>Inconceivable!</h1>";
        else if(
strtolower($input == 'wrex'))
            echo 
"Shepard.</h1>";
        else if(
str_replace(' '''strtolower($input)) == 'doctorwho' || str_replace(' '''strtolower($input)) == 'thedoctor' || str_replace(' '''strtolower($input)) == 'tardis')
            echo 
"Impossible!<br><br><img src='who.gif'></h1>";
        else if(
str_replace(' '''strtolower($input)) == 'montypython' || str_replace(' '''strtolower($input)) == 'spanishinquisition' || strtolower($input) == 'inquisition')
            echo 
"Impossible!<br><br><img src='/png/img/inquisition.jpg'></h1>";
        else if(
str_replace(' '''strtolower($input)) == 'harrypotter' || str_replace(' '''strtolower($input)) == 'ronweasley' || str_replace(' '''strtolower($input)) == 'hermionegranger' || strtolower($input) == 'snape' || strtolower($input) == 'dumbledore' || strtolower($input) == 'voldemort'|| strtolower($input) == 'hogwarts')
            echo 
"Impossible!<br><br><img src='snape.jpg'></h1>";
        else
        
// NEDDIH
        
echo "Impossible!</h1>";
        
$found_suggestions true;
        
$suggestions = array();
        foreach(
$words as $word) {
            
$sub periodic($word$e$size);
            if(
$sub) {
                
$suggestion $sub;
            } else {
                
$best_matches best_matches($db$word);
                if(
count($best_matches) == 0) {
                    
$found_suggestions false;
                    break;
                }
                
$suggestion implode('<br>'$best_matches);
            }
            
array_push($suggestions$suggestion);
        }
        if(
$found_suggestions) {
            echo 
'<p><br>...but you might try these <a href="" onclick="toggleSuggestions(); return false;">alternative spellings</a>:';
            echo 
'<br><table id="suggestions"' . ($suggest '' ' style="display: none;"') . '><tr>';
            foreach(
$words as $word) {
                echo 
"<td><b>$word</b></td>";
            }
            echo 
'</tr><tr>';
            foreach(
$suggestions as $suggestion) {
                echo 
"<td valign='top'>$suggestion</td>";
            }
            echo 
'</tr></table>';
        }
    }
}
echo 
"<div style='display: none;' id='post'>";
echo 
$input;
echo 
"</div>";
?>
<p class="footer"><br><a href="/">Home</a> &nbsp;<a href="source.php">View source code</a> &nbsp;<a href="api_readme.php">API</a></p>
</body>
</html>
Element Speller

Periodic Table Speller

Enter a word to see if it can be spelled using only element abbreviations from the Periodic Table.


Image: > > >

Use more: > >

"; $words = preg_replace('/[\W]+/', '', explode(' ', $input)); $size = ($length == "2"); foreach( $words as $word ) { $sub = periodic($word, $e, $size); if( !$sub ) $solvable = false; $solution = $solution." ".$sub; } if( $solvable ) { save($db, strtolower($solution)); echo trim( $solution ); if($name && $num && $mass && !$size) // pretty image URL for default settings $img = urlencode(trim($solution)).'.png'; else $img = "word.php?word=".urlencode(trim($solution))."&showname=".$name."&shownum=".$num."&showmass=".$mass."&size=$size"; echo "


Successfully spelled with element symbols"; $spelled = countspelled($db, strtolower($solution)); echo "


This phrase has been spelled $spelled time".($spelled == 1 ? "" : "s").'

'; } else {// HIDDEN if(in_array(strtolower($input), array('aradia', 'tavros', 'sollux', 'karkat', 'nepeta', 'kanaya', 'terezi', 'vriska', 'equius', 'gamzee', 'eridan', 'feferi', 'andrew hussie', 'john egbert', 'rose lalonde', 'dave strider', 'jade harley', 'jane crocker', 'roxy lalonde', 'dirk strider', 'jake english', 'homestuck', 'prospit', 'derse', 'zoosmell pooplord'))) echo ""; else if(strtolower($input == 'inconceivable')) echo "

Inconceivable!"; else if(strtolower($input == 'wrex')) echo "Shepard."; else if(str_replace(' ', '', strtolower($input)) == 'doctorwho' || str_replace(' ', '', strtolower($input)) == 'thedoctor' || str_replace(' ', '', strtolower($input)) == 'tardis') echo "Impossible!

"; else if(str_replace(' ', '', strtolower($input)) == 'montypython' || str_replace(' ', '', strtolower($input)) == 'spanishinquisition' || strtolower($input) == 'inquisition') echo "Impossible!

"; else if(str_replace(' ', '', strtolower($input)) == 'harrypotter' || str_replace(' ', '', strtolower($input)) == 'ronweasley' || str_replace(' ', '', strtolower($input)) == 'hermionegranger' || strtolower($input) == 'snape' || strtolower($input) == 'dumbledore' || strtolower($input) == 'voldemort'|| strtolower($input) == 'hogwarts') echo "Impossible!

"; else // NEDDIH echo "Impossible!"; $found_suggestions = true; $suggestions = array(); foreach($words as $word) { $sub = periodic($word, $e, $size); if($sub) { $suggestion = $sub; } else { $best_matches = best_matches($db, $word); if(count($best_matches) == 0) { $found_suggestions = false; break; } $suggestion = implode('
', $best_matches); } array_push($suggestions, $suggestion); } if($found_suggestions) { echo '


...but you might try these alternative spellings:'; echo '
'; foreach($words as $word) { echo ""; } echo ''; foreach($suggestions as $suggestion) { echo ""; } echo ''; } } } echo "

"; ?>