
Command
sudo apt-get install libpspell-dev
sudo apt-get install php8.0-pspell
sudo apt-get install aspell-en
Then restart your apache2 server with the following command
sudo service apache2 restart
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>'; // No suggestions, color red return '<span style="color:#FF0000;">'.$word.'</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.');
Comments (0)