PHP Classes

Hunspell FFI PHP Spell Check Library: Check the spelling of words in text using Hunspell

Recommend this page to a friend!
  Info   View files Example   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 70 All time: 10,256 This week: 673Up
Version License PHP version Categories
hunspell-ffi 1.0.0BSD License7.4Text processing, Libraries, PHP 7, FFI
Description 

Author

This package can check the spelling of words in text using Hunspell.

It can call the Hunspell library using the PHP FFI extension to perform several types of operations for checking words in a text. Currently, it can:

- Check if the spelling of a word is correct
- Suggest the correct spelling of a word
- Analyze the spelling of a word
- Generate a stem string for a word
- Etc...

Innovation Award
PHP Programming Innovation award winner
July 2021
Winner


Prize: One official elePHPant Plush Mascott
Hunspell is a powerful library for checking the spelling of words.

Since it is a library written in C++, it can be called from PHP projects using the PHP FFI extension.

This package provides a solution to call the Hunspell library using PHP FFI to access it as a regular PHP class.

Manuel Lemos
Picture of David Tamas
  Performance   Level  
Name: David Tamas <contact>
Classes: 5 packages by
Country: Hungary Hungary
Age: 37
All time rank: 311228 in Hungary Hungary
Week rank: 360 Up6 in Hungary Hungary Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<?php

require __DIR__ . '/hunspellFFI.php';
require
__DIR__ . '/hunspell.php';

$aff = '/usr/share/hunspell/hu_HU.aff';
$dic = '/usr/share/hunspell/hu_HU.dic';

$hs = new glex\hunspell($aff, $dic);

echo
"\n";
echo
"+=================================\n";
echo
"| SPELL\n";
echo
"+---------------------------------\n";
$spellWords = ['menu', 'menü', 'lábnyom', 'gyalogosan'];
foreach (
$spellWords as $word) {
   
$r = $hs->spell($word);
   
printf("| %s: %d\n", $word, $r);
}
echo
"+---------------------------------\n";

echo
"\n";
echo
"+=================================\n";
echo
"| SUGGEST\n";
echo
"+---------------------------------\n";
$word = "korcsoly";
$r = $hs->suggest($word);
printf("| %s: %d item\n", $word, count($r));
for (
$i = 0; $i < count($r); $i++) {
   
printf("| %d. %s\n", $i+1, $r[$i]);
}
echo
"+---------------------------------\n";

echo
"\n";
echo
"+=================================\n";
echo
"| ANALYZE\n";
echo
"+---------------------------------\n";
$word = "szavak";
$r = $hs->analyze($word);
printf("| %s: %d item\n", $word, count($r));
for (
$i = 0; $i < count($r); $i++) {
   
printf("| %d. %s\n", $i+1, $r[$i]);
}
echo
"+---------------------------------\n";


echo
"\n";
echo
"+=================================\n";
echo
"| STEM\n";
echo
"+---------------------------------\n";
$spellWords = ['menüvel', 'karácsonyi', 'volt', 'gyalogosan'];
foreach (
$spellWords as $word) {
   
$r = $hs->stem($word);
   
printf("| %s: %d\n", $word, count($r));
    for (
$i = 0; $i < count($r); $i++) {
       
printf("| - %d. %s\n", $i+1, $r[$i]);
    }
}
echo
"+---------------------------------\n";



echo
"\n";
echo
"+=================================\n";
echo
"| GENERATE\n";
echo
"+---------------------------------\n";
$spellWords = ['menüvel', 'karácsonyi', 'volt', 'gyalogosan'];
foreach (
$spellWords as $word) {
   
$r = $hs->generate('kéz', $word);
   
printf("| %s: %d\n", $word, count($r));
    for (
$i = 0; $i < count($r); $i++) {
       
printf("| - %d. %s\n", $i+1, $r[$i]);
    }
}
echo
"+---------------------------------\n";


echo
"\n";
echo
"+=================================\n";
echo
"| Add\n";
echo
"+---------------------------------\n";
$spellWords = ['glex', 'glexster', 'g-lex'];
foreach (
$spellWords as $word) {
   
$r = $hs->spell($word);
   
printf("| %s: %d\n", $word, $r);
}
echo
"+---------------------------------\n";

$hs->add('glex');
$hs->add('g-lex');


echo
"+---------------------------------\n";
$spellWords = ['glex', 'glexster', 'g-lex'];
foreach (
$spellWords as $word) {
   
$r = $hs->spell($word);
   
printf("| %s: %d\n", $word, $r);
}
echo
"+---------------------------------\n";

echo
"\n";
echo
"+=================================\n";
echo
"| Remove\n";
echo
"+---------------------------------\n";
$hs->remove('glex');
$spellWords = ['glex', 'glexster', 'g-lex'];
foreach (
$spellWords as $word) {
   
$r = $hs->spell($word);
   
printf("| %s: %d\n", $word, $r);
}
echo
"+---------------------------------\n";


echo
"\n";


Details

hunspell-ffi

PHP FFI interface for the hunspell spellchecker library and a wrapper library for the easier use.


  Files folder image Files  
File Role Description
Files folder imageheaders (8 files)
Accessible without login Plain text file example.php Example Example script
Plain text file hunspell.php Class Class source
Plain text file hunspellFFI.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  headers  
File Role Description
  Accessible without login Plain text file atypes.hxx Data Auxiliary data
  Accessible without login Plain text file header-ffi.h Data Auxiliary data
  Accessible without login Plain text file hunspell.h Data Auxiliary data
  Accessible without login Plain text file hunspell.hxx Data Auxiliary data
  Accessible without login Plain text file hunspell2-ffi.h Data Auxiliary data
  Accessible without login Plain text file hunvisapi.h Data Auxiliary data
  Accessible without login Plain text file php-hunspell.h Data Auxiliary data
  Accessible without login Plain text file w_char.hxx Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:70
This week:0
All time:10,256
This week:673Up