Introduction
In this article I will explain spell checking of words in a string using PHP. The "Pspell_new()" function is used to open a link to the appropriate language dictionary, and the "pspell_check()" function iterates over the word list. Before using this function obtain the instructions from the PHP manual at "www.php.net/pspell".
Example1
In the following example if a word in a paragraph or sentences and words that are incorrectly spelled are indentified, then pspell_check() function returns false.
<?php
$pspell_link = pspell_new("en");
if (pspell_check($pspell_link, "testt")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
?>
The following example checks the file line by line. You can have the previous listing check a file rather than a variable for misspelled words.
Example2
Note It is important to remember that pspell_check() returns false on a numeric string.
<?php
$file = "badspelling.txt";
//check spelling open dictionary link
$dict = pspell_new("en", "british", "", "", PSPELL_FAST);

Join the conversation! Your thoughts help the community grow.