PHP スペル チェック アプリを動作させようとしていますが、エンチャント拡張機能を使用しようとすると、単語のスペル ミスをチェックすることができません。
ウェブサーバー構成
- PHP バージョン 5.4.7
- Windows Server 2008
- IIS7
php.ini ファイルで、エンチャント拡張機能を有効にしました。例えば:
extension=php_enchant.dll
サンプルコード:
$broker = enchant_broker_init();
$tag = 'en_US';
$bprovides = enchant_broker_describe($broker);
echo "Current broker provides the following backend(s):\n";
print_r($bprovides);
$dicts = enchant_broker_list_dicts($broker);
echo "Current broker provides the following dictionaries:\n";
print_r($dicts);
enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, 'C:\php5.4.7\lib\enchant\MySpell');
if (enchant_broker_dict_exists($broker, $tag)) {
$dict = enchant_broker_request_dict($broker, $tag);
$word = 'soong';
$isCorrectlySpelled = enchant_dict_check($dict, $word);
if ($isCorrectlySpelled !== true) {
$suggestions = enchant_dict_suggest($dict, $word);
echo nl2br(print_r($suggestions, true));
} else {
echo 'The word is correctly spelt!';
}
}
enchant_broker_free($broker);
戻り値:
Current broker provides the following backend(s):
Array
(
[0] => Array
(
[name] => ispell
[desc] => Ispell Provider
[file] => C:\php5.4.7\libenchant_ispell.dll
)
[1] => Array
(
[name] => myspell
[desc] => Myspell Provider
[file] => C:\php5.4.7\libenchant_myspell.dll
)
)
Current broker provides the following dictionaries:
ただし、これは「soong」という単語のスペルが正しいかどうかはわかりません。