PHP code example of php-spellcheck / spellcheck-core
1. Go to this page and download the library: Download php-spellcheck/spellcheck-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-spellcheck / spellcheck-core example snippets
use PHPSpellcheck\Core\Checker\MisspellingFactory;
use PHPSpellcheck\Core\Checker\RunConfiguration;
use PHPSpellcheck\Core\Checker\RunStatisticsCollector;
use PHPSpellcheck\Core\Checker\SpellcheckRunner;
use PHPSpellcheck\Core\Diagnostics\DiagnosticCollector;
use PHPSpellcheck\Core\Dictionary\BuiltinDictionaries;
use PHPSpellcheck\Core\Dictionary\DictionaryLoader;
use PHPSpellcheck\Core\Dictionary\LocaleDictionaryMap;
use PHPSpellcheck\Core\Filter\DeduplicationFilter;
use PHPSpellcheck\Core\Filter\DictionaryFilter;
use PHPSpellcheck\Core\Filter\FilterChain;
use PHPSpellcheck\Core\Php\IdentifierKind;
use PHPSpellcheck\Core\Processor\HtmlProcessor;
use PHPSpellcheck\Core\Processor\PlaceholderProcessor;
use PHPSpellcheck\Core\Processor\ProcessorChain;
use PHPSpellcheck\Core\Report\BufferedWriter;
use PHPSpellcheck\Core\Report\TableReporter;
use PHPSpellcheck\Core\Source\PhpFileSource;
use PHPSpellcheck\Core\Speller\HunspellSpeller;
use PHPSpellcheck\Core\Tokenizer\IdentifierSplitter;
use PHPSpellcheck\Core\Tokenizer\ProseTokenizer;
use PHPSpellcheck\Core\Tokenizer\TokenizerRegistry;
$dictionary = (new DictionaryLoader())->loadAll(
BuiltinDictionaries::paths(['technical', 'php', 'symfony']),
);
$diagnostics = new DiagnosticCollector();
$statistics = new RunStatisticsCollector();
$runner = new SpellcheckRunner(
new ProcessorChain([new PlaceholderProcessor(), new HtmlProcessor()]),
new TokenizerRegistry([new IdentifierSplitter(4), new ProseTokenizer(4)]),
new HunspellSpeller(),
new FilterChain([new DictionaryFilter($dictionary), new DeduplicationFilter()]),
new MisspellingFactory(),
$diagnostics,
$statistics,
);
$source = new PhpFileSource(
paths: [__DIR__.'/src'],
exclude: ['vendor'],
kinds: IdentifierKind::DEFAULTS,
language: 'en_US',
projectDir: __DIR__,
diagnostics: $diagnostics,
statistics: $statistics,
);
$result = $runner->run([$source], new RunConfiguration(new LocaleDictionaryMap()));
$writer = new BufferedWriter();
(new TableReporter())->report($result, $writer);
echo $writer->getBuffer();
// 'Ciao %name%, hai %count% messagi' -> the column of "messagi" is 26,
// not the offset it would have in the cleaned-up string.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.