Location: PHPKode > scripts > PHP Spell Checker > php-spell-checker/examples/interactiveForm.php
<?php

//print_r($_POST);

$spellingResult = "";
if (isset($_POST['checkText'])) {
	require_once(dirname(__FILE__)."/../PHPSpellChecker.class.php");
	require_once(dirname(__FILE__)."/../HunSpellChecker.class.php");
	if ($_POST['version'] == "hunspell") {
		$spellCheck = new HunSpellChecker();
		$spellCheck->setHunspellPath(dirname(__FILE__)."/../hunspell");
	} else {
		$spellCheck = new PHPSpellChecker();
	}
	
	$result = $spellCheck->checkSpelling($_POST['text'], $_POST['locale']);
	if(count($result) == 0) {
		$spellingResult .= "Text is correctly spelled.\n\n";
	} else {
		$spellingResult .= "Text has mistakes !\nWords misspelled:";
		foreach ($result as $misspelledWord=>$suggestions) {
			$spellingResult .= "\n   ".$misspelledWord.":";
			$spellingResult .= "\n\tSuggestions: ".implode(", ", $suggestions);
		}
		$spellingResult .= "\n\n";
	}
	
	$warnings = $spellCheck->getWarnings();
	$errors = $spellCheck->getErrors();
	if ($warnings !== false) {
		$spellingResult .= "Warnings: ";
		foreach ($warnings as $warning) {
			foreach ($warning as $warningCode=>$warningMsg) {
				$spellingResult .= "\n\t[".$warningCode."] ".$warningMsg;
			}
		}
		$spellingResult .= "\n";
	} else {
		$spellingResult .= "Warnings: none\n";
	}
	
	if ($errors !== false) {
		$spellingResult .= "Errors: ";
		foreach ($errors as $error) {
			foreach ($error as $errorCode=>$errorMsg) {
				$spellingResult .= "\n\t[".$errorCode."] ".$errorMsg;
			}
		}
		$spellingResult .= "\n";
	} else {
		$spellingResult .= "Errors: none\n";
	}
}

?>


<html>
	<head>
		<title>PHP Spell Checker</title>
	</head>
	<body>
	
	Try out the PHP Spell Checker (please add the dictionaries first - see readme.txt)<hr/>
	<form action="" method="post">
		<table>
			<tr>
				<td>
					Enter text to check:<br/>
					<textarea name="text" rows="10" cols="60" style="border:1px solid #000;"><?php if (isset($_POST['text'])) print htmlentities($_POST['text']);?></textarea>
				</td>
				<td>
					Spell checking report:<br/>
					<textarea rows="10" cols="60" style="border:1px solid #000;"><?php print $spellingResult; ?></textarea>
				</td>
			</tr>
		</table>
		<br/><br/>
		
		Select language:<br/>
		<select name="locale">
			<option value="en-US"<?php if (isset($_POST['locale']) && $_POST['locale'] == 'en-US') print 'selected="selected"';?>>en-US</option>
			<option value="de-DE"<?php if (isset($_POST['locale']) && $_POST['locale'] == 'de-DE') print 'selected="selected"';?>>de-DE</option>
		</select>
		<br/><br/>
		
		Select method:<br/>
		<select name="version">
			<option value="php"<?php if (isset($_POST['version']) && $_POST['version'] == 'php') print 'selected="selected"';?>>PHP version</option>
			<option value="hunspell"<?php if (isset($_POST['version']) && $_POST['version'] == 'hunspell') print 'selected="selected"';?>>HunSpell version</option>
		</select>
		<br/><br/>
		
		<button type="submit" name="checkText" value="1">Check text</button>
	</form>
	
	</body>
</html>
Return current item: PHP Spell Checker