note 60235 deleted from ref.pspell by tularis

From: Date: Fri, 30 Dec 2005 22:07:47 +0000
Subject: note 60235 deleted from ref.pspell by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101009@lists.php.net to get a copy of this message
Note Submitter: beau_scott at hotmail dot com ---- I've extended upon webmaster at script-tease dot net sample spell checker to better handle punctuation numbers, etc.: <? /** * Checks spelling of $string. Whole phrases can be sent in, too, and each word will be checked. * Returns an associative array of mispellings and their suggested spellings * @param string $string Phrase to be checked * @return array */ function checkSpelling ( $string ) { echo $string . "<br>"; // Make word list based word boundries $wordlist = preg_split('/\s/',$string); // Filter words $words = array(); for($i = 0; $i < count($wordlist); $i++) { $word = trim($wordlist[$i]); if(!preg_match('/[A-Za-z]/', $word)) continue; $word = preg_replace('/[^\w\']*(.+)/', '\1', $word); $word = preg_replace('/([^\W]*)[^\w\']*$/', '\1', $word); $word = trim($word); if(!in_array($word, $words, true)) $words[] = $word; } $misspelled = $return = array(); $int = pspell_new('en'); foreach ($words as $value) if (!pspell_check($int, $value)) $misspelled[] = $value; foreach ($misspelled as $value) $return[$value] = pspell_suggest($int, $value); return $return; } ?>

« previous php.notes (#101009) next »