This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

PHP spell check library updated for PHP7

1.7.3 2018-09-11 21:21 UTC

This package is auto-updated.

Last update: 2021-05-20 01:20:18 UTC


PHP spell check library.

Latest Stable Version License Build Status Coverage Status

Currently supported backends:


With Composer:

$ composer require mekras/php-speller


  1. Create a text source object from string, file or something else using one of the Mekras\Speller\Source\Source implementations (see Sources below).
  2. Create some speller instance (Hunspell, Ispell or any other implementation of the Mekras\Speller\Speller).
  3. Execute Speller::checkText() method.
use Mekras\Speller\Hunspell\Hunspell;
use Mekras\Speller\Source\StringSource;

$source = new StringSource('Tiger, tigr, burning bright');
$speller = new Hunspell();
$issues = $speller->checkText($source, ['en_GB', 'en']);

echo $issues[0]->word; // -> "tigr"
echo $issues[0]->line; // -> 1
echo $issues[0]->offset; // -> 7
echo implode(',', $issues[0]->suggestions); // -> tiger, trig, tier, tigris, tigress

You can list languages supported by backend:

/** @var Mekras\Speller\Speller $speller */

See examples for more info.

Source encoding

For aspell, hunspell and ispell source text encoding should be equal to dictionary encoding. You can use IconvSource to convert source.


This backend uses aspell program, so it should be installed in the system.

use Mekras\Speller\Aspell\Aspell;

$speller = new Aspell();

Path to binary can be set in constructor:

use Mekras\Speller\Aspell\Aspell;

$speller = new Aspell('/usr/local/bin/aspell');


  • aspell allow to specify only one language at once, so only first item taken from $languages argument in Ispell::checkText().


This backend uses hunspell program, so it should be installed in the system.

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();

Path to binary can be set in constructor:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell('/usr/local/bin/hunspell');

You can set additional dictionary path:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();

You can specify custom dictionaries to use:

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();
$speller->setCustomDictionaries(['tech', 'titles']);


This backend uses ispell program, so it should be installed in the system.

use Mekras\Speller\Ispell\Ispell;

$speller = new Ispell();

Path to binary can be set in constructor:

use Mekras\Speller\Ispell\Ispell;

$speller = new Ispell('/usr/local/bin/ispell');


  • ispell allow to use only one dictionary at once, so only first item taken from $languages argument in Ispell::checkText().


Sources — is an abstraction layer allowing spellers receive text from different sources like strings or files.


Reads text from file.

use Mekras\Speller\Source\FileSource;

$source = new FileSource('/path/to/file.txt');

You can specify file encoding:

use Mekras\Speller\Source\FileSource;

$source = new FileSource('/path/to/file.txt', 'windows-1251');


Use string as text source.

use Mekras\Speller\Source\StringSource;

$source = new StringSource('foo', 'koi8-r');

Meta sources

Additionally there is a set of meta sources, which wraps other sources to perform extra tasks.


Return user visible text from HTML.

use Mekras\Speller\Source\HtmlSource;

$source = new HtmlSource(
    new StringSource('<a href="#" title="Foo">Bar</a> Baz')
echo $source->getAsString(); // Foo Bar Baz

Encoding detected via DOMDocument::$encoding.


This is a meta-source which converts encoding of other given source:

use Mekras\Speller\Source\IconvSource;
use Mekras\Speller\Source\StringSource;

// Convert file contents from windows-1251 to koi8-r.
$source = new IconvSource(
    new FileSource('/path/to/file.txt', 'windows-1251'),


Loads text from XLIFF files.

use Mekras\Speller\Source\XliffSource;

$source = new XliffSource(__DIR__ . '/fixtures/test.xliff');

Source filters

Filters used internally to filter out all non text contents received from source. In order to save original word location (line and column numbers) all filters replaces non text content with spaces.

Available filters: