<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Spell check - delete.me.uk</title>
<link rel="stylesheet" href="word.style" title="style me baby" />
</head>
<body>
<h1><a href="/">delete.me.uk</a>: Spell Checker</h1>
<?php
if ($HTTP_GET_VARS["word"])
checkWord($HTTP_GET_VARS["word"], $HTTP_GET_VARS["lang"]);
else
promptForWord();
// spit out a form to prompt for a word and language variation
function promptForWord() {
?>
<form action="word.blah" method="get">
<h2>Enter Your Word</h2>
<p><label for="wordbox">word</label>: <input type="text" id="wordbox" name="word" maxlenght="100" value="<?php echo htmlspecialchars($HTTP_GET_VARS["word"]); ?>" tabindex="1" /></p>
<fieldset>
<legend>Language Variation</legend>
<p><input type="radio" id="checkBritish" name="lang" value="british" tabindex="2" checked="checked" /> <label for="checkBritish">British</label></p>
<p><input type="radio" id="checkAmerican" name="lang" value="american" tabindex="3" /> <label for="checkAmerican">American</label></p>
<p><input type="radio" id="checkCanadian" name="lang" value="canadian" tabindex="4" /> <label for="checkCanadian">Canadian</label></p>
</fieldset>
<p><input type="submit" value="check" /></p>
</form>
<?php
}
// spit out the results
function checkWord($word, $languageVariation) {
// check dictionary
$result = checkSpelling($word, $languageVariation);
$word = stripslashes($word);
// connection to dictionary failed
if ($result == null) {
?>
<div id="result">
<h2>Results for checking <strong><?php echo htmlspecialchars($word); ?></strong></h2>
<p>A connection to the Pspell server failed. You can <a href="word.blah?word=<?php echo htmlspecialchars($word); ?>&lang=<?php echo htmlspecialchars($languageVariation); ?>" title="Check "<?php echo htmlspecialchars($word); ?>" using the <?php echo htmlspecialchars($languageVariation); ?> variation again">check "<?php echo htmlspecialchars($word); ?>" using the <?php echo htmlspecialchars($languageVariation); ?> variation again</a> or <a href="word.blah" title="Return to the form">return to the form</a>.</p>
</div>
<?php
// word was spelt correctly
} else if ($result == "correct") {
?>
<div id="result">
<h2>Results for checking <strong><?php echo htmlspecialchars($word); ?></strong></h2>
<p>The spelling was <strong>correct</strong>.</p>
<p>You can <a href="http://www.dictionary.com/search?q=<?php echo htmlspecialchars($word); ?>" title="Search dictionary.com">search for "<?php echo htmlspecialchars($word); ?>" on dictionary.com</a>, or <a href="word.blah" title="Return to the form">check another word</a>.</p>
</div>
<?php
// word was spelt worng, results are spat back out
} else {
?>
<div id="result">
<h2>Results for checking <strong><?php echo htmlspecialchars($word); ?></strong></h2>
<p>"<?php echo htmlspecialchars($word); ?>" <strong>wasn't found</strong> in the dictionary. Here are the suggested replacements:</p>
<ul>
<?php
for ($i = 0; $i < count($result); $i++)
printf ("\t<li><a href=\"http://www.dictionary.com/search?q=%s\" title=\"Search dictionary.com for "%s"\">%s</a></li>\n", htmlspecialchars($result[$i]), htmlspecialchars($result[$i]), htmlspecialchars($result[$i]));
?>
</ul>
<p><a href="word.blah" title="Return to the form">Check another word</a>.</p>
</div>
<?php
}
}
// check word in db
function checkSpelling($word, $languageVariation) {
$word = trim ($word);
if (!$languageVariation) $languageVariation = "british";
//$word = AddSlashes ($word);
// make connection
$pspellLink = pspell_new("en", $languageVariation);
if ($pspellLink) {
// check if correct spelling
$checkIt = pspell_check ($pspellLink, $word);
if ($checkIt == true)
return "correct";
// if not, check for suggestions
else
return pspell_suggest ($pspellLink, $word);
} else
return null;
}
?>
<div id="info">
<h2>Spell Check Information</h2>
<p>This script was created by <a href="/about" rel="author">Paul Sowden</a>.</p>
<p>It uses <a href="http://www.php.net" title="PHP"><abbr title="PHP: Hypertext Preprocessor">PHP</abbr></a> and <a href="http://pspell.sourceforge.net/" title="Pspell">pspell</a>.</p>
<p>The <a href="word.source">source code</a> is available under the GNU GPL.</p>
</div>
</body>
</html>