note 60235 added to ref.pspell

From: Date: Fri, 30 Dec 2005 20:12:33 +0000
Subject: note 60235 added to ref.pspell
Groups: php.notes 
Request: Send a blank email to php-notes+get-101006@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.pspell.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60235 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60235&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60235&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101006) next »