# Aspell PHP

The Aspell library is used to verify the spelling of a word. It is the result of an open source project run by Kevin Atkinson. In order for PHP to use Aspell, the functions must be loaded as an extension. At the time of this writing, no win32 extension existed for Aspell, so its functionality is available to UNIX users only. Mark Musone added Aspell support to PHP.

integer aspell_new(string dictionary, string personal_words)
Use aspell_new to load a dictionary into the system. An identifier is returned that must be used in subsequent calls to Aspell functions. The second argument is optional and specifies a personal dictionary.

<?
//create a test sentence
$text = "Thiss sentense haz some spellling erors."; //load dictionary$aspell_link = aspell_new('english');
//tokenize sentence
for($word = strtok($text, ' ');
$word != '';$word = strtok(' '))
{
//check for unrecognized words
if(!aspell_check($aspell_link,$token))
{
//try checking raw version
if(!aspell_check_raw($aspell_link,$token))
{
//word not recognized, get
suggestions
$suggestion = aspell_suggest($aspell_link, $token); print("<B>Unrecognized word:</B>$token<BR> ");
while(list($index,$word) =
each($suggestion)) { print("$val<BR> ");
}
print("<BR> ");
}
}
}
?>