Pspell php что это
Функции Pspell
Содержание
User Contributed Notes 14 notes
echo spellCheck ( ‘PHP is a reflecktive proegramming langwage origenaly dezigned for prodewcing dinamic waieb pagges.’ );
?>
OUTPUT: PHP is a reflective programming language originally designed for producing dynamic Web pages.
Manuall php installation on Debian/Ubuntu will require you to:
apt-get install libpspell-dev
There appears to be a problem currently affecting PSpell functionality on Windows machines.
Currently, the compiled build of PHP5 for Windows does not by default include PSpell, and to activate these functions the Windows user has to (a) install GNU ASpell; (b) copy the file aspell-15.dll to a directory in the Windows «Path» statement (typically C:\Windows\System32); (c) install one or more ASpell dictionaries; (d) enable the PSpell extension to PHP by adding a reference to php_pspell.dll in the php.ini file, and moving the file itself to the main PHP directory.
However, when this has all been done and PSpell appears to have been fully activated, there remains a problem. While all the PSpell functions work as specified when referenced from the «main» body of PHP code, if they are placed within a PHP function, the system reports that it is unable to find any word lists for the specified dictionary (whichever one is chosen).
I have a sample of PSpell-using code (taken from the SAMS book PHP 5 In Practice) which works perfectly on a Unix-based Web Server, but which fails with the indicated error message on a range of Windows machines.
To get round the error on Windows where the word list can’t be found inside functions, take the call to pspell_new() out of the function and pass the return value to your function, i.e.
compiling php with pspell on debian sarge:
apt-get install aspell libaspell15 libaspell-dev libpspell-dev
if previous tries have failed or it is not functioning properly, unpack the php source again and configure / compile in a fresh tree
Back in 10/2002 csnyder at chxo dot com wrote the first comment about the spell functions, and wrote a very sophisticated spell check with a direct call to aspell. In a similar vein, I wrote a simplified a PHP function that will spell check a string and insert tags before and after the misspelled words. Auto-correction is not offered.
For this to work on your system, see if /usr/local/bin/aspell list runs from the shell. It needs to get input from standard input. You may not be able to run apell without the path for PHP because the PATH variable may be different in the PHP invocation from a shell invocation.
Aspell Author Here.
Since Aspell 0.50, Pspell is no longer used. It is not necessary to download and install the Pspell package, only Aspell 0.50 (or better) is required. Aspell now provided a backwards compatibility interface for programs expecting the old Pspell interface (such as PHP).
Even though Aspell now provided a new «Aspell» interface this, the PHP Pspell interface is the one you want to use. The Aspell PHP interface is the one used with a *very* old version of Aspell as the manual says.
Sorry if this is confusing, but it is not really my fought as I have no control over PHP development. Eventually a new Aspell interface should be provided for PHP which uses the new Aspell interface provided with Aspell 0.50 but for now the Pspell interface will work just fine.
Note: If you wish to use an older version of Aspell (_before_ 0.50) than both Aspell and Pspell are required.
For those will problems installing on Win32 with IIS:
Symptom: browser just hangs when calling pspell function. Running PHP.exe from command line causes pspell to claim that there is a corrupt file. Running Aspell works just fine on the command line.
You need new data files:
You can download and get more information about it here:
http://wiki.wordpress.org/SpellCheck
Just replace the data directory in C:\Programs Files\Aspell\ with the new data directory you downloaded.
If you use red hat or fedora, you may need to is use
yum install pspell-devel
(fixes: configure: error: Cannot find pspell)
In response to csnyder’s comment about calling aspell instead of using the aspell or pspell libs:
If you are running a low traffic site this will work fine and it’s a good idea.
If, however, you have many customers using your spell checking script, this method does not scale well and you should consider spending the time to make the libs work properly.
Easy way to make a spellchecker:
I had the same problems after following the detailed instructions for installing on windows but was able to solve them by doing the following:
first, I copied all the files in the data directory of the aspell install (ie. C:\Program Files\Aspell\data) to a unix machine and ran dos2unix on all of the files and then copied them back.
second, added this line before the pspell_new(«en») call
pspell_config_create(«en»);
hope this works for you too.
If you are receiving the error message:
PSPELL couldn’t open the dictionary. reason:
No word lists can be found for the language «en».
Add following lines prior to calling pspell_check:
$pspell_config = pspell_config_create(«en»);
$pspell_link = pspell_new_config($pspell_config);
As an alternative to mucking about with the compiled-in aspell/pspell functions, which only check word by word, one could write a script that calls aspell as a shell exec to check a whole block of text:
Not sure about Linux or Windows, but installing aspell on FreeBSD was trivially easy from the ports collection. No doubt such a script could be easily modified to use ispell instead if you’d rather.
pspell_new
(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
pspell_new — Загружает новый словарь
Описание
pspell_new() открывает новый словарь и возвращает экземпляр PSpell\Dictionary для использования в других функциях pspell.
Более подробную информацию и примеры можно найти в руководстве по pspell на сайте:» http://aspell.net/.
Список параметров
Параметр spelling определяет вариант проверки орфографии для языков с более чем одним вариантом правописания, таких как английский. Известные значения: ‘american’, ‘british’, и ‘canadian’.
Параметр jargon содержит дополнительную информацию для различения двух различных списков слов, имеющих одинаковые параметры language и spelling.
Параметр encoding это кодировка, в которой, как ожидается, даны слова. Допустимые значения: ‘utf-8’, ‘iso8859-*’, ‘koi8-r’, ‘viscii’, ‘cp1252’, ‘machine unsigned 16’, ‘machine unsigned 32’. Этот параметр ещё не проверен достаточно хорошо, поэтому будьте осторожны при его использовании.
Возвращаемые значения
Возвращает экземпляр PSpell\Dictionary в случае успешного выполнения или false в случае возникновения ошибки.
Список изменений
Версия | Описание |
---|---|
8.1.0 | Возвращает экземпляр PSpell\Dictionary ; ранее возвращался ресурс (resource). |
Примеры
Пример #1 Пример использования pspell_new()
pspell_new_personal
pspell_new_personal — Загружает новый словарь с персональным списком слов
Описание
pspell_new_personal() открывает новый словарь с персональным списком слов. Список слов может быть модифицирован и сохранён функцией pspell_save_wordlist(), если потребуется. Однако замещающие пары не сохраняются. Для сохранения замещающих пар вы должны создать конфигурацию, используя pspell_config_create(), установить файл персонального списка слов функцией pspell_config_personal(), установить файл для замещающих пар функцией pspell_config_repl(), и открыть новый словарь с помощью pspell_new_config().
Более подробную информацию и примеры можно найти в руководстве по pspell на сайте:» http://aspell.net/.
Список параметров
Код языка, который состоит из двухбуквенного кода языка по стандарту ISO 639 и необязательного двубуквенного кода страны по стандарту ISO 3166 после тире или подчеркивания.
Определяет вариант проверки орфографии для языков с более чем одним вариантом правописания, таких, как английский. Известные значения: ‘american’, ‘british’, и ‘canadian’.
Дополнительная информацию для различения двух различных списков слов, имеющих одинаковые параметры language и spelling.
Кодировка, в которой, как ожидается, даны слова. Допустимые значения: utf-8, iso8859-*, koi8-r, viscii, cp1252, machine unsigned 16, machine unsigned 32.
Возвращаемые значения
Возвращает ссылку на словарь для использования в других функциях pspell.
Функции Pspell
Содержание
Коментарии
As an alternative to mucking about with the compiled-in aspell/pspell functions, which only check word by word, one could write a script that calls aspell as a shell exec to check a whole block of text:
http://chxo.com/scripts/spellcheck.php
(there is a view-source option)
Not sure about Linux or Windows, but installing aspell on FreeBSD was trivially easy from the ports collection. No doubt such a script could be easily modified to use ispell instead if you’d rather.
Aspell Author Here.
Since Aspell 0.50, Pspell is no longer used. It is not necessary to download and install the Pspell package, only Aspell 0.50 (or better) is required. Aspell now provided a backwards compatibility interface for programs expecting the old Pspell interface (such as PHP).
Even though Aspell now provided a new «Aspell» interface this, the PHP Pspell interface is the one you want to use. The Aspell PHP interface is the one used with a *very* old version of Aspell as the manual says.
Sorry if this is confusing, but it is not really my fought as I have no control over PHP development. Eventually a new Aspell interface should be provided for PHP which uses the new Aspell interface provided with Aspell 0.50 but for now the Pspell interface will work just fine.
Note: If you wish to use an older version of Aspell (_before_ 0.50) than both Aspell and Pspell are required.
I had the same problems after following the detailed instructions for installing on windows but was able to solve them by doing the following:
first, I copied all the files in the data directory of the aspell install (ie. C:\Program Files\Aspell\data) to a unix machine and ran dos2unix on all of the files and then copied them back.
second, added this line before the pspell_new(«en») call
pspell_config_create(«en»);
hope this works for you too.
Easy way to make a spellchecker:
In response to csnyder’s comment about calling aspell instead of using the aspell or pspell libs:
If you are running a low traffic site this will work fine and it’s a good idea.
If, however, you have many customers using your spell checking script, this method does not scale well and you should consider spending the time to make the libs work properly.
For those will problems installing on Win32 with IIS:
Symptom: browser just hangs when calling pspell function. Running PHP.exe from command line causes pspell to claim that there is a corrupt file. Running Aspell works just fine on the command line.
You need new data files:
You can download and get more information about it here:
http://wiki.wordpress.org/SpellCheck
Just replace the data directory in C:\Programs Files\Aspell\ with the new data directory you downloaded.
If you are receiving the error message:
PSPELL couldn’t open the dictionary. reason:
No word lists can be found for the language «en».
Add following lines prior to calling pspell_check:
$pspell_config = pspell_config_create(«en»);
$pspell_link = pspell_new_config($pspell_config);
compiling php with pspell on debian sarge:
apt-get install aspell libaspell15 libaspell-dev libpspell-dev
if previous tries have failed or it is not functioning properly, unpack the php source again and configure / compile in a fresh tree
If you use red hat or fedora, you may need to is use
yum install pspell-devel
(fixes: configure: error: Cannot find pspell)
Back in 10/2002 csnyder at chxo dot com wrote the first comment about the spell functions, and wrote a very sophisticated spell check with a direct call to aspell. In a similar vein, I wrote a simplified a PHP function that will spell check a string and insert tags before and after the misspelled words. Auto-correction is not offered.
There appears to be a problem currently affecting PSpell functionality on Windows machines.
Currently, the compiled build of PHP5 for Windows does not by default include PSpell, and to activate these functions the Windows user has to (a) install GNU ASpell; (b) copy the file aspell-15.dll to a directory in the Windows «Path» statement (typically C:\Windows\System32); (c) install one or more ASpell dictionaries; (d) enable the PSpell extension to PHP by adding a reference to php_pspell.dll in the php.ini file, and moving the file itself to the main PHP directory.
However, when this has all been done and PSpell appears to have been fully activated, there remains a problem. While all the PSpell functions work as specified when referenced from the «main» body of PHP code, if they are placed within a PHP function, the system reports that it is unable to find any word lists for the specified dictionary (whichever one is chosen).
I have a sample of PSpell-using code (taken from the SAMS book PHP 5 In Practice) which works perfectly on a Unix-based Web Server, but which fails with the indicated error message on a range of Windows machines.
To get round the error on Windows where the word list can’t be found inside functions, take the call to pspell_new() out of the function and pass the return value to your function, i.e.
echo spellCheck ( ‘PHP is a reflecktive proegramming langwage origenaly dezigned for prodewcing dinamic waieb pagges.’ );
?>
OUTPUT: PHP is a reflective programming language originally designed for producing dynamic Web pages.
Manuall php installation on Debian/Ubuntu will require you to:
pspell_new_config
(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
pspell_new_config — Загружает новый словарь с установками на основе заданной конфигурации
Описание
Список параметров
Возвращаемые значения
Возвращает экземпляр PSpell\Dictionary в случае успешного выполнения или false в случае возникновения ошибки.
Список изменений
Версия | Описание |
---|---|
8.1.0 | Параметр config теперь ожидает экземпляр PSpell\Config ; ранее ожидался ресурс (resource). |
8.1.0 | Возвращает экземпляр PSpell\Dictionary ; ранее возвращался ресурс (resource). |
Примеры
Пример #1 Пример использования pspell_new_config()
User Contributed Notes 1 note
Today I ran into an interesting problem that I thought I’d share here to save the next developer that ends up in the same situation a whole lot of trouble. I have been running PHP5 as a FastCGI module on a Windows IIS server, and I recently installed the Aspell library and enabled the pspell extension in my php.ini file. I also installed the English Aspell dictionary. But when I went to use pspell, I was getting ambiguous errors that would terminate script execution without warning.
So I started to break things down, and came to the conclusion that the following code successfully executed its first line, but broke on the last line with the call to pspell_new_config: