Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <?php
  2. $config_dic= pspell_config_create ('en');
  3.  
  4. <?php
  5. function orthograph($string)
  6. {
  7. // Suggests possible words in case of misspelling
  8. $config_dic = pspell_config_create('en');
  9.  
  10. // Ignore words under 3 characters
  11. pspell_config_ignore($config_dic, 3);
  12.  
  13. // Configure the dictionary
  14. pspell_config_mode($config_dic, PSPELL_FAST);
  15. $dictionary = pspell_new_config($config_dic);
  16.  
  17. // To find out if a replacement has been suggested
  18. $replacement_suggest = false;
  19.  
  20. $string = explode('', trim(str_replace(',', ' ', $string)));
  21. foreach ($string as $key => $value) {
  22. if(!pspell_check($dictionary, $value)) {
  23. $suggestion = pspell_suggest($dictionary, $value);
  24.  
  25. // Suggestions are case sensitive. Grab the first one.
  26. if(strtolower($suggestion [0]) != strtolower($value)) {
  27. $string [$key] = $suggestion [0];
  28. $replacement_suggest = true;
  29. }
  30. }
  31. }
  32.  
  33. if ($replacement_suggest) {
  34. // We have a suggestion, so we return to the data.
  35. return implode('', $string);
  36. } else {
  37. return null;
  38. }
  39. }
  40.  
  41. <?php
  42. $search = $_POST['input'];
  43. $suggestion_spell = orthograph($search);
  44. if ($suggestion_spell) {
  45. echo "Try with this spelling : $suggestion_spell";
  46. }
  47.  
  48. $dict = pspell_new ("en");
  49. if (!pspell_check ($dict, "lappin")) {
  50. $suggestions = pspell_suggest ($dict, "lappin");
  51. foreach ($suggestions as $suggestion) {
  52. echo "Did you mean: $suggestion?<br />";
  53. }
  54. }
  55. // Suggests possible words in case of misspelling
  56. $config_dic = pspell_config_create('en');
  57.  
  58. // Ignore words under 3 characters
  59. pspell_config_ignore($config_dic, 3);
  60.  
  61. // Configure the dictionary
  62. pspell_config_mode($config_dic, PSPELL_FAST);
  63. $dictionary = pspell_new_config($config_dic);
  64. $config_dic = pspell_config_create ('en');
  65. pspell_config_personal($config_dic, 'path / perso.pws');
  66. pspell_config_ignore($config_dic , 2);
  67. pspell_config_mode($config_dic, PSPELL_FAST);
  68. $dic = pspell_new_config($config_dic);
  69. pspell_add_to_personal($dic, "word");
  70. pspell_save_wordlist($dic);
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement