Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $config_dic= pspell_config_create ('en');
- <?php
- function orthograph($string)
- {
- // Suggests possible words in case of misspelling
- $config_dic = pspell_config_create('en');
- // Ignore words under 3 characters
- pspell_config_ignore($config_dic, 3);
- // Configure the dictionary
- pspell_config_mode($config_dic, PSPELL_FAST);
- $dictionary = pspell_new_config($config_dic);
- // To find out if a replacement has been suggested
- $replacement_suggest = false;
- $string = explode('', trim(str_replace(',', ' ', $string)));
- foreach ($string as $key => $value) {
- if(!pspell_check($dictionary, $value)) {
- $suggestion = pspell_suggest($dictionary, $value);
- // Suggestions are case sensitive. Grab the first one.
- if(strtolower($suggestion [0]) != strtolower($value)) {
- $string [$key] = $suggestion [0];
- $replacement_suggest = true;
- }
- }
- }
- if ($replacement_suggest) {
- // We have a suggestion, so we return to the data.
- return implode('', $string);
- } else {
- return null;
- }
- }
- <?php
- $search = $_POST['input'];
- $suggestion_spell = orthograph($search);
- if ($suggestion_spell) {
- echo "Try with this spelling : $suggestion_spell";
- }
- $dict = pspell_new ("en");
- if (!pspell_check ($dict, "lappin")) {
- $suggestions = pspell_suggest ($dict, "lappin");
- foreach ($suggestions as $suggestion) {
- echo "Did you mean: $suggestion?<br />";
- }
- }
- // Suggests possible words in case of misspelling
- $config_dic = pspell_config_create('en');
- // Ignore words under 3 characters
- pspell_config_ignore($config_dic, 3);
- // Configure the dictionary
- pspell_config_mode($config_dic, PSPELL_FAST);
- $dictionary = pspell_new_config($config_dic);
- $config_dic = pspell_config_create ('en');
- pspell_config_personal($config_dic, 'path / perso.pws');
- pspell_config_ignore($config_dic , 2);
- pspell_config_mode($config_dic, PSPELL_FAST);
- $dic = pspell_new_config($config_dic);
- pspell_add_to_personal($dic, "word");
- pspell_save_wordlist($dic);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement