note 55863 deleted from ref.pspell by victor

From: Date: Tue, 16 Aug 2005 08:07:05 +0000
Subject: note 55863 deleted from ref.pspell by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93713@lists.php.net to get a copy of this message
Note Submitter: bradlis7 at bradlis7 dot com ---- Here's a function to printout a spell checked paragraph. $dividers contains all of the punctuation commonly used so it doesn't check those. <?php function spellcheck($text) { $dividers=array("\n","\r",".",",", "(",")","!","?","\"",";",":"," "); $word = ''; for($i = 0; $i < strlen($text); $i++) { //count through each letter $ch = substr($text,$i,1); //get the letter if(in_array($ch,$dividers)) { //if it's a divider,check the previous word, and print the divider if($word != '') { if(!pspell_check($pspell_link,$word)) { //when you're mouse goes over the word, it should show up. $retval.="<span class='standout' title=\"Suggestions: "; $suggestions = pspell_suggest($pspell_link,$word); foreach($suggestions as $s) { $retval.=str_replace("\"",'&quot;',$s)." "; } $retval.="\">$word</span>"; } else { $retval.=$word; } $word=''; //reset the word } $retval.=($ch=="\n"?"<br>\n":$ch); } else { //add the letter to the current word if it's not a divider character $word.=$ch; } } return $retval; } ?> It puts the suggestions as a span title, and I'm not sure if all browsers will show a tooltip, but firefox and IE6 both show them. Counting through each character is probably really slow, but I couldn't find very many functions that would do the job.

« previous php.notes (#93713) next »