note 60236 added to ref.pspell

From: Date: Fri, 30 Dec 2005 21:13:02 +0000
Subject: note 60236 added to ref.pspell
Groups: php.notes 
Request: Send a blank email to php-notes+get-101007@lists.php.net to get a copy of this message
hehe, forgot to remove the echo $string line... whoops ;) Should be: <? /** * 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 ) { // 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+60236 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60236&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60236&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101007) next »