PHP Spellchecker Library


January 30th, 2020

PHP Spellchecker Library

PHP Spellchecker is a library providing a way to spellcheck multiple sources of text by many spellcheckers. The library provides an abstraction layer with a unified interface for various spellcheckers with support for the following out of the box:

Here’s a quick example from the documentation using the Aspell spellchecker:

2use PhpSpellcheck\SpellChecker\Aspell;
4// if you made the default aspell installation on you local machine
5$aspell = Aspell::create();
7$misspellings = $aspell->check('mispell', ['en_US'], ['from_example']);
9foreach ($misspellings as $misspelling) {
10 $misspelling->getWord(); // 'mispell'
11 $misspelling->getLineNumber(); // '1'
12 $misspelling->getOffset(); // '0'
13 $misspelling->getSuggestions(); // ['misspell', ...]
14 $misspelling->getContext(); // ['from_example']

Here’s an example from the documentation for checking spelling in a file:

2// spellchecking a file
3$misspellings = $aspell->check(new File('path/to/file.txt'), ['en_US'], ['from_file']);
4foreach ($misspellings as $misspelling) {
5 $misspelling->getWord();
6 $misspelling->getLineNumber();
7 $misspelling->getOffset();
8 $misspelling->getSuggestions();
9 $misspelling->getContext();

Be sure to check out the PHP-Spellchecker Documentation for complete details on installation and usage. You can check out the source code on GitHub at tigitz/php-spellchecker.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.