tigitz /
php-spellchecker
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | use PhpSpellcheck\MisspellingFinder; |
||
| 6 | use PhpSpellcheck\MisspellingHandler\EchoHandler; |
||
| 7 | use PhpSpellcheck\Spellchecker\Aspell; |
||
| 8 | use PhpSpellcheck\TextInterface; |
||
| 9 | use PhpSpellcheck\TextProcessor\TextProcessorInterface; |
||
| 10 | |||
| 11 | require_once __DIR__ . '/../vendor/autoload.php'; |
||
| 12 | |||
| 13 | // My custom text processor that replaces "_" by " " |
||
| 14 | $customTextProcessor = new class () implements TextProcessorInterface { |
||
| 15 | public function process(TextInterface $text): TextInterface |
||
| 16 | { |
||
| 17 | $contentProcessed = str_replace('_', ' ', $text->getContent()); |
||
| 18 | |||
| 19 | return $text->replaceContent($contentProcessed); |
||
| 20 | } |
||
| 21 | }; |
||
| 22 | |||
| 23 | $misspellingFinder = new MisspellingFinder( |
||
| 24 | Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path |
||
| 25 | new EchoHandler(), // Handles all the misspellings found by echoing their information |
||
| 26 | $customTextProcessor |
||
| 27 | ); |
||
| 28 | |||
| 29 | // using a string |
||
| 30 | $misspellingFinder->find('It\'s_a_mispelling', ['en_US']); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | // word: mispelling | line: 1 | offset: 7 | suggestions: mi spelling,mi-spelling,misspelling | context: [] |
||
| 32 |