Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. $pspell = pspell_new('en','canadian','','utf-8',PSPELL_FAST);
  3.  
  4. function spellCheckWord($word) {
  5.     global $pspell;
  6.     $autocorrect = TRUE;
  7.  
  8.     // Take the string match from preg_replace_callback's array
  9.     $word = $word[0];
  10.    
  11.     // Ignore ALL CAPS
  12.     if (preg_match('/^[A-Z]*$/',$word)) return $word;
  13.  
  14.     // Return dictionary words
  15.     if (pspell_check($pspell,$word))
  16.         return $word;
  17.  
  18.     // Auto-correct with the first suggestion, color green
  19.     if ($autocorrect && $suggestions = pspell_suggest($pspell,$word))
  20.         return '<span style="color:#00FF00;">'.current($suggestions).'</span>';
  21. }
  22.  
  23. function spellCheck($string) {
  24.     return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
  25. }
  26.  
  27. echo spellCheck('PHP is a reflecktive proegramming langwage origenaly dezigned for prodewcing dinamic waieb pagges.');
  28. ?>
Add Comment
Please, Sign In to add comment