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:
1<?php 2use PhpSpellcheck\SpellChecker\Aspell; 3 4// if you made the default aspell installation on you local machine 5$aspell = Aspell::create(); 6 7$misspellings = $aspell->check('mispell', ['en_US'], ['from_example']); 8 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']15}
Here’s an example from the documentation for checking spelling in a file:
1<?php 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();10}
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.
0 comments:
Post a Comment
Thanks