Php spell checker open source
Show
Check misspellings from any text source with the most popular PHP spellchecker. AboutPHP-Spellchecker is a spellchecker abstraction library for PHP. By providing a unified interface for many different spellcheckers, you’re able to swap out spellcheckers without extensive rewrites. Using PHP-Spellchecker can eliminate vendor lock-in, reduce technical debt, and improve the testability of your code. Features
PHP-Spellchecker is a welcoming project for new contributors. Want to make your first open source contribution? Check the roadmap, pick one task, open an issue and we'll help you go through it 🤓🚀 InstallVia Composer $ composer require tigitz/php-spellchecker UsageCheck out the documentation and examples Using the spellchecker directlyYou can check misspellings directly from a
// if you made the default aspell installation on your local machine
$aspell = Aspell::create();
// or if you want to use binaries from Docker
$aspell = new Aspell(new CommandLine(['docker','run','--rm', '-i', 'starefossen/aspell']));
$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']
} Using the MisspellingFinder orchestratorYou can also use an opinionated
Following the well-known Unix philosophy:
// My custom text processor that replaces "_" by " "
$customTextProcessor = new class implements TextProcessorInterface
{
public function process(TextInterface $text): TextInterface
{
$contentProcessed = str_replace('_', ' ', $text->getContent());
return $text->replaceContent($contentProcessed);
}
};
$misspellingFinder = new MisspellingFinder(
Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path
new EchoHandler(), // Handles all the misspellings found by echoing their information
$customTextProcessor
);
// using a string
$misspellingFinder->find('It\'s_a_mispelling', ['en_US']);
// word: mispelling | line: 1 | offset: 7 | suggestions: mi spelling,mi-spelling,misspelling | context: []
// using a TextSource
$inMemoryTextProvider = new class implements SourceInterface
{
public function toTexts(array $context): iterable
{
yield new Text('my_mispell', ['from_source_interface']);
// t() is a shortcut for new Text()
yield t('my_other_mispell', ['from_named_constructor']);
}
};
$misspellingFinder->find($inMemoryTextProvider, ['en_US']);
//word: mispell | line: 1 | offset: 3 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_source_interface"]
//word: mispell | line: 1 | offset: 9 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_named_constructor"] RoadmapThe project is still in its initial phase, requiring more real-life usage to stabilize its final 1.0.0 API. Global
Sources
Text processors
Spell checkers
Handlers
Tests
VersioningWe follow SemVer v2.0.0. There still are many design decisions that should be confronted with real-world usage before thinking about a v1.0.0 stable release:
TestingSpell checkers come in many different forms, from HTTP API to command line tools. PHP-Spellchecker wants to ensure real-world usage is OK, so it contains integration tests. To run these, spellcheckers need to all be available during tests execution. The most convenient way to do it is by using Docker and avoid polluting your local machine. DockerRequires $ make build # build container images $ make setup # start spellcheckers container $ make tests-dox You can also specify PHP version, dependency version target and if you want coverage. Coverage is only supported on PHP 8.0 for now. $ PHP_VERSION=8.0 DEPS=LOWEST WITH_COVERAGE="true" make tests-dox Run LocallyTodo Environment variablesIf spellcheckers execution paths are different than their default values (e.g., ContributingPlease see CONTRIBUTING. Credits
LicenseThe MIT License (MIT). Please see license file for more information. Logo: Elements taken for the final rendering are Designed by rawpixel.com / Freepik. How do I spell check in PHP?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']);. What is the best free spell check app?Grammarly Keyboard is the app's mobile keyboard extension that works with both iOS and Android devices. If you're using Grammarly for basic grammar checking, you'll benefit the most from the free version.
How do you spell check in JavaScript?JavaScript SpellCheck : The leading spellchecker plugin for JS. Includes "spellcheck-as-you-type" and "spellchecking in a dialog window" functions.. Install in 5 Minutes.. Fully .Net, PHP, ASP and Java Compatible.. Available as native TinyMCE SpellChecker and CKEditor Spell Check plugins.. |