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:
<?php
use PhpSpellcheck\SpellChecker\Aspell;
// if you made the default aspell installation on you local machine
$aspell = Aspell::create();
$misspellings = $aspell->check('mispell', ['en_US'], ['from_example']);
foreach ($misspellings as $misspelling) {
$misspelling->getWord(); // 'mispell'
$misspelling->getLineNumber(); // '1'
$misspelling->getOffset(); // '0'
$misspelling->getSuggestions(); // ['misspell', ...]
$misspelling->getContext(); // ['from_example']
}
Here’s an example from the documentation for checking spelling in a file:
<?php
// spellchecking a file
$misspellings = $aspell->check(new File('path/to/file.txt'), ['en_US'], ['from_file']);
foreach ($misspellings as $misspelling) {
$misspelling->getWord();
$misspelling->getLineNumber();
$misspelling->getOffset();
$misspelling->getSuggestions();
$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.
0 comments:
Post a Comment
Thanks