PHP code example of mekras / php-speller

1. Go to this page and download the library: Download mekras/php-speller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mekras / php-speller example snippets


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

/** @var Mekras\Speller\Speller $speller */
print_r($speller->getSupportedLanguages());

use Mekras\Speller\Aspell\Aspell;

$speller = new Aspell();

use Mekras\Speller\Aspell\Aspell;

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

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

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();

use Mekras\Speller\Hunspell\Hunspell;

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

use Mekras\Speller\Hunspell\Hunspell;

$speller = new Hunspell();
$speller->setDictionaryPath('/var/spelling/custom');

use Mekras\Speller\Hunspell\Hunspell;

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

use Mekras\Speller\Ispell\Ispell;

$speller = new Ispell();

use Mekras\Speller\Ispell\Ispell;

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

use Mekras\Speller\Source\FileSource;

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

use Mekras\Speller\Source\FileSource;

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

use Mekras\Speller\Source\StringSource;

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

use Mekras\Speller\Source\HtmlSource;

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

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

use Mekras\Speller\Source\XliffSource;

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