CakeFest 2024: The Official CakePHP Conference

pspell_new

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

pspell_new新規辞書をロードする

説明

pspell_new(
    string $language,
    string $spelling = "",
    string $jargon = "",
    string $encoding = "",
    int $mode = 0
): PSpell\Dictionary|false

pspell_new() は、新規の辞書をロードして PSpell\Dictionary クラスのインスタンスを返します。 このインスタンスは、他の pspell 関数で使用されます。

詳細な情報および例については、pspell の Web サイト :» http://aspell.net/ にあるインラインマニュアルを参照ください。

パラメータ

language

パラメータ language は、2 文字の ISO 639 言語コードと オプションでダッシュまたはアンダースコアの後に 2 文字の ISO 3166 国コードからなる言語コードです。

spelling

パラメータ spelling は、英語のように複数のスペルがある言語に関して スペルの指定を行うものです。指定可能な値は、 'american', 'british', 'canadian'です。

jargon

パラメータ jargon は、同じ language および spelling パラメータを有する 2 つの異なる単語リストを区別するための 追加情報を有しています。

encoding

パラメータ encoding は、単語のエンコーディングとして 予想されるものです。有効な値は、'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32' です。このパラメータはよくテストされていないため、 使用する際には注意してください。

mode

パラメータ mode は、スペルチェッカの動作モードです。 使用可能なモードを以下に示します。

  • PSPELL_FAST - 高速モード (修正候補の数は最小)
  • PSPELL_NORMAL - 通常モード (修正候補はより多い)
  • PSPELL_BAD_SPELLERS - 低速モード (修正候補は多い)
  • PSPELL_RUN_TOGETHER - つながった単語を複合語 (legal compound)として考慮します。この場合、"thecat" には二つの 単語の間に空白はありませんが複合語となります。この設定の変更は pspell_check() から返される結果にのみ影響します。 設定変更後も pspell_suggest() は修正候補を返します。
mode は、これらのさまざまな定数を用いたビットマスクです。 しかし PSPELL_FASTPSPELL_NORMAL および PSPELL_BAD_SPELLERS は相反するため、 この中のひとつを選択する必要があります。

戻り値

成功した場合に、 PSpell\Dictionary クラスのインスタンスを返します。 失敗した場合に false を返します

変更履歴

バージョン 説明
8.1.0 PSpell\Dictionary クラスのインスタンスを返すようになりました。 これより前のバージョンでは、 リソース を返していました。

例1 pspell_new()

<?php
$pspell
= pspell_new("en", "", "", "",
(
PSPELL_FAST|PSPELL_RUN_TOGETHER));
?>

add a note

User Contributed Notes 2 notes

up
10
wookie
15 years ago
Just as a small tip, I noticed that when you call pspell_new multiple times, php does not free memory usage when the resource is destroyed, but only when your entire script has completely finished. So if you create a pspell_link resource and you intend to use it again somewhere else, instead of calling pspell_new again, keep track of your original pspell_link resource instantiation, and use it again, your script will run much more efficiently.

I was switching between 16 dictionaries by just calling a new pspell_new everytime, my memory usage on the server grew until i hit a failure/php core dump. :-/ So i stored each pspell resource in an array keyed by language, and checked if the resource existed first, before creating one if needed.

I hope that helps someone.
up
1
allan at wagawaga dot dk
15 years ago
I think the language and spelling parameters differs on different PHP versions and/or aspell/UNIX distributions.

My PHP 5.2.6 Debian ignores the spelling parameter.

Instead:

For Americans use en_US as language.
For British use en_GB (not en_UK)
For Canadian use en_CA
To Top