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
//word not recognized, get
$suggestion =
aspell_suggest($aspell_link, $token);
print("<B>Unrecognized word:</B>
$token<BR> ");
while(list($index, $word) =
print("$val<BR> ");
print("<BR> ");

boolean aspell_check(integer link, string word)
The aspell_check function returns true if the word argument is found in the dictionary specified by the link argument. This function attempts to trim extraneous characters before validating the spelling.

boolean aspell_check_raw(integer link, string word)
This function behaves like aspell_check, except that it makes no attempt to trim extraneous characters.

array aspell_suggest(integer link, string word)
The aspell_suggest function returns an array of suggested spellings for a word. The link argument is an integer returned by the aspell_new function.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

PHP Topics