函式名: enchant_broker_set_ordering()
描述: enchant_broker_set_ordering() 函式用於設定拼寫檢查器引擎的優先順序順序。
用法: enchant_broker_set_ordering(EnchantBroker $broker, string $tag, string $ordering)
引數:
- $broker: EnchantBroker 物件,拼寫檢查器的代理。
- $tag: 字串,拼寫檢查引擎的標籤。
- $ordering: 字串,用於設定拼寫檢查引擎的排序順序。可以是 "prioritize"(優先),"match"(匹配),"default"(預設)之一。
返回值: 成功時返回true,失敗時返回false。
示例:
// 建立拼寫檢查器代理
$broker = enchant_broker_init();
// 設定拼寫檢查器引擎的優先順序順序
enchant_broker_set_ordering($broker, "en_US", "prioritize, match");
// 獲取英文(美國)字典
$dicts = enchant_broker_describe($broker);
$en_us_dict = null;
foreach ($dicts as $dict) {
if ($dict['lang'] == 'en_US') {
$en_us_dict = $dict['name'];
break;
}
}
// 建立拼寫檢查器
$speller = enchant_broker_request_dict($broker, $en_us_dict);
// 設定當前字典
enchant_broker_set_dict($broker, $speller);
// 檢查拼寫
$word = "aple";
if (enchant_dict_check($speller, $word)) {
echo "$word is spelled correctly.";
} else {
$suggestions = enchant_dict_suggest($speller, $word);
echo "$word is misspelled. Suggestions: " . implode(", ", $suggestions);
}
// 釋放資源
enchant_broker_free_dict($speller);
enchant_broker_free($broker);
在此示例中,我們首先建立了一個拼寫檢查器代理並設定了拼寫檢查器引擎的優先順序順序。然後我們獲取英文(美國)字典並建立了一個拼寫檢查器。最後,我們使用拼寫檢查器檢測一個拼寫錯誤的單詞並提供糾正建議。在使用完畢後,我們清理並釋放了資源。