note 51163 added to function.pspell-check

From: Date: Tue, 22 Mar 2005 13:32:10 +0000
Subject: note 51163 added to function.pspell-check
Groups: php.notes 
Request: Send a blank email to php-notes+get-86778@lists.php.net to get a copy of this message
I felt that it would help to expand on batch spell checking using this function. The previously posted example implodes using spaces as the separator for each word. There are however situations in which doing this will not return the desired result. For example, "Hello, I like coding." will return an array with two problems, "Hello," and "coding.", both these words are spelt correctly, but pspell_check() will deem them as spelled incorrectly because a comma or a period is being passed in to the function along with the word. The following example allows you to extract only the words (using regular expressions to ignore grammar such as periods or commas) in to an array and then add in html font tags to highlight all words spelled incorrectly red before returning the string. <? Function SpellCheck($string) { $pspell_link = pspell_new("en"); preg_match_all("/[A-Z\']{1,16}/i", $string, $words); for ($i = 0; $i < count($words[0]); $i++) { if (!pspell_check($pspell_link, $words[0][$i])) { $string = str_replace($words[0][$i], "<font color=\"#FF0000\">" . $words[0][$i] . "</font>", $string); } } return $string; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.pspell-check.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51163 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51163&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51163&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51163&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51163&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51163&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51163&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86778) next »