2024 年 PHP 日本研討會

pspell_config_data_dir

(PHP 5, PHP 7, PHP 8)

pspell_config_data_dir語言資料檔案的位置

說明

pspell_config_data_dir(PSpell\Config $config, string $directory): bool

警告

此函式目前沒有說明文件;僅提供其參數列表。

返回值

成功時返回 true,失敗時返回 false

版本異動

版本 說明
8.1.0 現在,config 參數需要一個 PSpell\Config 實例;先前需要的是一個 資源
新增註記

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

alexxed at gmail dot com
17 年前
以下是如何在您不想或無法使用系統上安裝的字典時使用 pspell 的範例。
<?
$text_to_check = 'I can sspeak English';
// 選擇性。稍微清理一下文字
$clean_text_to_check = preg_replace('/[^a-z0-9\-\.!;]+/i', ' ', $text_to_check);
// 取得單字列表
$word_list = preg_split('/\s+/', $clean_text_to_check);

$pspell_config = pspell_config_create("en", null, null, 'utf-8');

// 如果您想要的 aspell 字典尚未安裝,
// 請複製 aspell 字典並在此設定字典的路徑
pspell_config_data_dir($pspell_config, "/home/alex/dictionaries/");
pspell_config_dict_dir($pspell_config, "/home/alex/dictionaries/");
$pspell_link = pspell_new_config($pspell_config);

foreach($word_list as $word) {

if (!pspell_check($pspell_link, trim($word))) {
$suggestions = pspell_suggest($pspell_link, trim($word));

echo $word . ' 拼字錯誤 <br />';
foreach ($suggestions as $suggestion) {
echo "\t 可能的拼法:$suggestion <br />";
}
}
} else {
// 拼寫正確
}
}
?>
To Top