PHPackages                             mekras/php-speller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mekras/php-speller

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mekras/php-speller
==================

PHP spell check library

2.3.0(3y ago)68413.6k↓57.9%24[2 issues](https://github.com/mekras/php-speller/issues)[4 PRs](https://github.com/mekras/php-speller/pulls)MITPHPPHP &gt;=7.4

Since May 8Pushed 1y ago4 watchersCompare

[ Source](https://github.com/mekras/php-speller)[ Packagist](https://packagist.org/packages/mekras/php-speller)[ RSS](/packages/mekras-php-speller/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (32)Used By (0)

php-speller
===========

[](#php-speller)

PHP spell check library.

[![Latest Stable Version](https://camo.githubusercontent.com/f4a6565d359262f9347784499d4d8ae52a82cf2002bbf01af4a2447470b790c4/68747470733a2f2f706f7365722e707567782e6f72672f6d656b7261732f7068702d7370656c6c65722f762f737461626c652e706e67)](https://packagist.org/packages/mekras/php-speller)[![License](https://camo.githubusercontent.com/a71a1afdfad8feaefb3509d23e881dad78be94c336a8e9721d633468366ce184/68747470733a2f2f706f7365722e707567782e6f72672f6d656b7261732f7068702d7370656c6c65722f6c6963656e73652e706e67)](https://packagist.org/packages/mekras/php-speller)[![Build Pipeline](https://github.com/mekras/php-speller/actions/workflows/build.yml/badge.svg)](https://github.com/mekras/php-speller/actions/workflows/build.yml)

Currently supported backends:

- [aspell](http://aspell.net/);
- [hunspell](http://hunspell.sourceforge.net/);
- [ispell](https://www.cs.hmc.edu/~geoff/ispell.html).

Installation
------------

[](#installation)

With [Composer](http://getcomposer.org/):

```
$ composer require mekras/php-speller

```

Usage
-----

[](#usage)

1. Create a text source object from string, file or something else using one of the `Mekras\Speller\Source\Source` implementations (see [Sources](#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 */
print_r($speller->getSupportedLanguages());
```

See [examples](examples/) for more info.

### Source encoding

[](#source-encoding)

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

Aspell
------

[](#aspell)

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');
```

### Custom Dictionary

[](#custom-dictionary)

You can use a custom dictionary for aspell. The dictionary needs to be in the following format:

```
personal_ws-1.1 [lang] [words]

```

Where `[lang]` shout be the shorthand for the language you are using (e.g. `en`) and `[words]` is the count of words inside the dictionary. **Beware** that there should no spaces at the end of words. Each word should be listed in a new line.

```
$aspell = new Aspell();
$aspell->setPersonalDictionary(new Dictionary('/path/to/custom.pws'));
```

### Important

[](#important)

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

Hunspell
--------

[](#hunspell)

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();
$speller->setDictionaryPath('/var/spelling/custom');
```

You can specify custom dictionaries to use:

```
use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();
$speller->setDictionaryPath('/my_app/spelling');
$speller->setCustomDictionaries(['tech', 'titles']);
```

Ispell
------

[](#ispell)

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');
```

### Important

[](#important-1)

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

Sources
-------

[](#sources)

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

### FileSource

[](#filesource)

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');
```

### StringSource

[](#stringsource)

Use string as text source.

```
use Mekras\Speller\Source\StringSource;

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

Meta sources
------------

[](#meta-sources)

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

### HtmlSource

[](#htmlsource)

Return user visible text from HTML.

```
use Mekras\Speller\Source\HtmlSource;

$source = new HtmlSource(
    new StringSource('Bar Baz')
);
echo $source->getAsString(); // Foo Bar Baz
```

Encoding detected via [DOMDocument::$encoding](http://php.net/manual/en/class.domdocument.php#domdocument.props.encoding).

### IconvSource

[](#iconvsource)

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'),
    'koi8-r'
);
```

### XliffSource

[](#xliffsource)

Loads text from [XLIFF](http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html)files.

```
use Mekras\Speller\Source\XliffSource;

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

Source filters
--------------

[](#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:

- [StripAllFilter](src/Source/Filter/StripAllFilter.php) — strips all input text;
- [HtmlFilter](src/Source/Filter/HtmlFilter.php) — strips HTML tags.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 70.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~241 days

Total

26

Last Release

1177d ago

Major Versions

1.x-dev → v2.02019-01-17

PHP version history (9 changes)v1.00PHP ~5.4

v1.4PHP &gt;=5.5

1.x-devPHP &gt;=5.6

v2.0PHP ^7.2

2.0.2PHP ~7.1

2.1.0PHP ^7.1

2.1.4PHP &gt;=7.1

2.2.0PHP &gt;=7.3

2.3.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f59cdbde66f36f1f86dad783d2f79e64c17ffdcd0771f73b96b7d9d7ee37b364?d=identicon)[Mekras](/maintainers/Mekras)

---

Top Contributors

[![mekras](https://avatars.githubusercontent.com/u/192067?v=4)](https://github.com/mekras "mekras (90 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")[![icanhazstring](https://avatars.githubusercontent.com/u/883543?v=4)](https://github.com/icanhazstring "icanhazstring (11 commits)")[![genericmilk](https://avatars.githubusercontent.com/u/1846127?v=4)](https://github.com/genericmilk "genericmilk (1 commits)")[![ibarrajo](https://avatars.githubusercontent.com/u/1480657?v=4)](https://github.com/ibarrajo "ibarrajo (1 commits)")[![mmetayer](https://avatars.githubusercontent.com/u/5301298?v=4)](https://github.com/mmetayer "mmetayer (1 commits)")[![olivierpontier](https://avatars.githubusercontent.com/u/50582517?v=4)](https://github.com/olivierpontier "olivierpontier (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![caugner](https://avatars.githubusercontent.com/u/495429?v=4)](https://github.com/caugner "caugner (1 commits)")[![rouliane](https://avatars.githubusercontent.com/u/1978756?v=4)](https://github.com/rouliane "rouliane (1 commits)")[![cniry](https://avatars.githubusercontent.com/u/2609142?v=4)](https://github.com/cniry "cniry (1 commits)")[![dergel](https://avatars.githubusercontent.com/u/322951?v=4)](https://github.com/dergel "dergel (1 commits)")

---

Tags

aspellhunspellispellphpspellingspellingaspellhunspellispell

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mekras-php-speller/health.svg)

```
[![Health](https://phpackages.com/badges/mekras-php-speller/health.svg)](https://phpackages.com/packages/mekras-php-speller)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[phpactor/phpactor

PHP refactoring and intellisense tool for text editors

1.9k17.1k1](/packages/phpactor-phpactor)[illuminate/process

The Illuminate Process package.

44869.2k99](/packages/illuminate-process)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
