Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pspell = pspell_new('en','canadian','','utf-8',PSPELL_FAST);
- function spellCheckWord($word) {
- global $pspell;
- $autocorrect = TRUE;
- // Take the string match from preg_replace_callback's array
- $word = $word[0];
- // Ignore ALL CAPS
- if (preg_match('/^[A-Z]*$/',$word)) return $word;
- // Return dictionary words
- if (pspell_check($pspell,$word))
- return $word;
- // Auto-correct with the first suggestion, color green
- if ($autocorrect && $suggestions = pspell_suggest($pspell,$word))
- return '<span style="color:#00FF00;">'.current($suggestions).'</span>';
- }
- function spellCheck($string) {
- return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
- }
- echo spellCheck('PHP is a reflecktive proegramming langwage origenaly dezigned for prodewcing dinamic waieb pagges.');
- ?>
Add Comment
Please, Sign In to add comment