PHP Conference Japan 2024

pspell_config_create

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

pspell_config_create建立用於開啟字典的設定

說明

pspell_config_create(
    字串 $language,
    字串 $spelling = "",
    字串 $jargon = "",
    字串 $encoding = ""
): PSpell\Config

建立用於開啟字典的設定。

pspell_config_create() 的語法與 pspell_new() 非常相似。事實上,先使用 pspell_config_create() 緊接著使用 pspell_new_config() 將會產生完全相同的結果。然而,在建立新的設定後,您也可以在呼叫 pspell_new_config() 之前使用 pspell_config_*() 函式來利用一些進階功能。

更多資訊與範例,請參考線上 pspell 手冊網站:» http://aspell.net/

參數

language(語言)

language 參數是語言代碼,它由兩個字母的 ISO 639 語言代碼和一個可選的兩個字母的 ISO 3166 國家代碼組成,國家代碼以破折號或底線分隔。

spelling(拼寫)

spelling 參數是用於指定拼寫方式,適用於具有多種拼寫的語言,例如英語。已知的值為 'american'、'british' 和 'canadian'。

jargon(術語)

jargon 參數包含額外資訊,用於區分具有相同語言和拼寫參數的兩個不同單字列表。

encoding(編碼)

encoding 參數是預期單字的編碼。有效值為 'utf-8'、'iso8859-*'、'koi8-r'、'viscii'、'cp1252'、'machine unsigned 16'、'machine unsigned 32'。此參數的測試並不完整,因此使用時請務必小心。

返回值

返回一個 PSpell\Config 實例。

更新日誌

版本 說明
8.1.0 現在返回一個 PSpell\Config 實例;先前返回的是 資源

範例

範例 #1 pspell_config_create()

<?php
$pspell_config
= pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell = pspell_new_personal($pspell_config, "en");
?>

新增筆記

使用者貢獻的筆記 1 則筆記

mshort at mail dot com
1 年前
如果您嘗試使用多個自訂字典,尤其是在您沒有系統 aspell 字典目錄的 sudo 權限時,這可能會有幫助⋯⋯
我使用「aspell create master」建立了三個自訂字典(或者說是單字列表),並找到了一種使用它們的方法⋯⋯
1) 建立 3 個單字列表,每行一個單字,分別為 wordlistA.txt、wordlistB.txt 和 wordlistC.txt。
2) 建立 3 個主字典檔... 使用 aspell --lang=en create master ./my_LANG-dictA.rws < wordlistA.txt - 針對 B 和 C 重複此步驟 (lang 語言需要已安裝,我想任何語言應該都可以)。
3) 建立 3 個多字典檔,my_LANGA.multi,內容:add my_LANG-dictA.rws) - 針對 B 和 C 重複此步驟。其中 my_LANGA 可以是任何名稱,大小寫需與 aspell 手冊中說明的一致。
4) 使用 pspell 搭配其中任何一個 (A、B 或 C) ...
<?php
$pspell_config
= pspell_config_create('my_LANGC', '', ''. 'utf-8');
pspell_config_dict_dir($pspell_config, <my_LANGC.multi 的位置>);
if ((
$pspell = pspell_new_config($pspell_config)) == false) {
echo
'LANGC 的 pspell_new_config() 失敗!');
} else {
$word = 'PHPisgreat';
if (
pspell_check($pspell, $word)) {
echo
"$word: 拼寫正確";
} else {
$suggestions = pspell_suggest($pspell, $word);
echo
"$word: 建議拼寫: $suggestions";
}
}
?>

pspell_config_create() 的語言參數是 .multi 檔案的基底名稱 (不含副檔名)。
請注意,我沒有 $HOME/.aspell.conf 檔案。
請注意,我的 .multi 和 .rws 檔案位於同一個目錄中,我認為這是必要的。
建立主字典檔後,就不再需要單字列表檔案。
To Top