codeconjure/php-hunspell

PHP binding for the Hunspell spell-checker and morphological analyzer

Maintainers

Package info

github.com/connorhu/php-hunspell

Language:C++

Type:php-ext

Ext name:ext-hunspell

pkg:composer/codeconjure/php-hunspell

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-05-20 13:15 UTC

This package is auto-updated.

Last update: 2026-05-20 13:20:33 UTC


README

CI

PHP 8.2+ binding for the Hunspell spell-checker and morphological analyzer. Exposes spell-check, suggestions, morphological analysis (analyze, stem, generate), runtime dictionary mutation (add, addWithAffix, remove, addDictionary), and dictionary metadata.

Requirements

  • PHP 8.2 or newer (NTS or ZTS)
  • libhunspell 1.6.0 or newer + its development headers
  • pkg-config
  • A C++17-capable compiler

Install via PIE (recommended)

pie install codeconjure/php-hunspell

Install via phpize

git clone https://github.com/connorhu/php-hunspell.git
cd php-hunspell
phpize
./configure --enable-hunspell
make
sudo make install
echo "extension=hunspell.so" | sudo tee /etc/php/conf.d/hunspell.ini

Usage

<?php
$dict = new Hunspell\Dictionary('/path/to/hu_HU.aff', '/path/to/hu_HU.dic');

$dict->spell('szótár');                   // bool
$dict->suggest('szóter');                 // list<string>
$dict->stem('szótárak');                  // list<string>
$dict->analyze('szótárak');               // list<Hunspell\Analysis>

$a = $dict->analyze('szótárak')[0];
$a->getRaw();                             // raw morph string
$a->getFields();                          // array<string, list<string>>
$a->get('st');                            // stems (list<string>)
$a->has('hy');                            // bool — does this analysis carry a hyphenation hint?

$dict->generate('ház', 'kertben');        // generate form of ház matching kertben's morphology
$dict->addWithAffix('Németh', 'világ');   // proper noun inherits világ's affix flags

Error handling

try {
    $dict = new Hunspell\Dictionary($aff, $dic);
} catch (Hunspell\Exception\Exception $e) {
    // Any Hunspell-layer failure (currently only DictionaryLoadException)
}

License

PHP License 3.01.