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
if($_GET['length'] == 2)
$r2 = "checked";
else
$r1 = "checked";
if(!isset($_GET['word']))
$first = 1;
?>
<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" <? echo $_GET['num'] || $first ? 'checked' : ''; ?>><label for="chkNum">Show number</label>
<input id="chkName" type="checkbox" name="name" value="1" <? echo $_GET['name'] || $first ? 'checked' : ''; ?>><label for="chkName">Show name</label>
<input id="chkMass" type="checkbox" name="mass" value="1" <? echo $_GET['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="<? echo $_GET['suggest'] ?: '0'; ?>"></form>
<?PHP
require 'functions.php';
$e = elements();
$solvable = true;
if($_GET["word"] != null) {
echo "<h1 style='margin-top: 1em'>";
$words = preg_replace('/[\W]+/', '', explode(' ', $_GET["word"]));
$size = ($_GET['length'] == "2");
foreach( $words as $word ) {
$sub = periodic($word, $e, $size);
if( !$sub )
$solvable = false;
$solution = $solution." ".$sub;
}
if( $solvable ) {
save(strtolower($solution));
echo trim( $solution );
if($_GET['name'] && $_GET['num'] && $_GET['mass'] && !$size) // pretty image URL for default settings
$img = urlencode(trim($solution)).'.png';
else
$img = "word.php?word=".urlencode(trim($solution))."&showname=".$_GET['name']."&shownum=".$_GET['num']."&showmass=".$_GET['mass']."&size=$size";
echo "<br><br><br><img src='$img' alt='Successfully spelled with element symbols'>";
$spelled = countspelled(strtolower($solution));
echo "</h1><p><br>This phrase has been spelled $spelled time".($spelled == 1 ? "" : "s").'</p>';
} else {
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($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"' . ($_GET['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 $_GET["word"];
echo "</div>";
?>
<p class="footer"><br><a href="/">Home</a> <a href="source.php">View source code</a> <a href="api_readme.php">API</a></p>
</body>
</html>