Hướng dẫn install pspell php extension

If you have the libraries needed add the --with-pspell[=dir] option when compiling PHP.

Show

Note: Note to Win32 Users

In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled "How do I add my PHP directory to the PATH on Windows". Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system's PATH), this is not recommended. This extension requires the following files to be in the PATH: aspell-15.dll from the bin folder of the aspell installation.

Win32 support requires at least aspell version 0.50.

chapman at wtinds dot com

2 years ago

If you are compiling v7.3.x under CentOS 8, you will need to first enable PowerTools, then install aspell-devel - otherwise aspell-devel will not be available to you:

sudo dnf config-manager --set-enabled PowerTools
sudo dnf install -y aspell-devel

Then in your configure line, just use:

--with-pspell

NOT

--with-pspell=/some/dir

juliusdavies at gmail dot com

13 years ago

Aspell + PHP + Windows was giving me just crazy crashes with this simple test file:

$pspell_link = pspell_new("en");
?>

Running "php -f test.php" directly from a DOS prompt shed some light:

----------------
The file "C:\Program Files\Aspell\data/iso8859-1.dat" can not be opened for reading.pell\dict/en-only.rws:
----------------

To fix it I needed to "dos2unix" all the files in Aspell's C:\Program Files\Aspell\data\ directory.  (Convert them from CRLF to just LF line endings).

  1. I am not positive but you may need xcode and xcode command line tools installed for this to work. This article might be helpful.

  2. Install MacPorts if you don't have it already

  3. Install aspell and the dictionary of your choice (I used "en"):

    sudo port install aspell aspell-dict-en

  4. note: for the next commands, you need to know the version of php you're running on MAMP. You can find this in the MAMP preferences under the PHP tab. For me it's 5.5.18

    Download the php source for the version of php you are running, unarchive it, and move into the pspell source directory:

    cd ~/Downloads/php-5.5.18/ext/pspell

  5. Now (being sure to use the proper phpize binary for your php version) do:

    /Applications/MAMP/bin/php/php5.5.18/bin/phpize

You should see something like:

 Configuring for:
 PHP Api Version:         20121113
 Zend Module Api No:      20121212
 Zend Extension Api No:   220121212

Next:

./configure --with-php-config=/Applications/MAMP/bin/php/php5.5.18/bin/php-config --with-pspell=/opt/local/

And finally, build the module file:

make
  1. You should now have two files inside the ./modules/ directory: aspell.so and aspell.la - copy them into your php's extensions directory:

    cp ./modules/* /Applications/MAMP/bin/php/php5.5.18/lib/php/extensions/no-debug-non-zts-20121212

  2. Now add the extension to your configuration file in /Applications/MAMP/bin/php/php5.5.18/conf/php.ini

    extension=pspell.so

  3. Finally, restart your MAMP servers and (hopefully) you are good to go!

Hướng dẫn install pspell php extension

  • What is PHP-Spellchecker ?
  • Quick Start
  • Architecture
  • Characters and Encoding
  • Using Context
  • Aspell
  • Hunspell
  • Ispell
  • PHP Pspell
  • LanguageTools
  • JamSpell
  • MultiSpellchecker
  • Create Custom
  • EchoHandler
  • Create Custom
  • File
  • Directory
  • MultiSource
  • Create Custom
  • Markdown Remover
  • Create Custom
  • Tests

edit on GitHub


The purpose of Pspell (Portable Spell Checker Interface Library) was to provide a generic interface to the system spelling checking libraries.

PHP’s Pspell extension, while retaining its current name, now uses the Aspell library.

Install

PHP PSpell extension installation is lacking documentation so your best bet is probably a google search for your OS.

Usage

Now that PHP PSpell extension is installed on your system, let's see how to spellcheck a word using PHP-Spellchecker and PHP PSpell extension.

Spellcheck

check('mispell', ['en_US'], ['from_example']);
foreach ($misspellings as $misspelling) {
    $misspelling->getWord(); // 'mispell'
    $misspelling->getLineNumber(); // '1'
    $misspelling->getOffset(); // '0'
    $misspelling->getSuggestions(); // ['misspell', ...]
    $misspelling->getContext(); // ['from_example']
}

Or if you want to check a file instead:

check(new File('path/to/file.txt'), ['en_US'], ['from_file']);
foreach ($misspellings as $misspelling) {
    $misspelling->getWord();
    $misspelling->getLineNumber();
    $misspelling->getOffset();
    $misspelling->getSuggestions();
    $misspelling->getContext();
}

Available dictionaries

getSupportedLanguages();

Check the tests for more examples.