note 55863 added to ref.pspell
| From: | bradlis7 at bradlis7 dot com | Date: | Tue, 16 Aug 2005 00:40:20 +0000 |
| Subject: | note 55863 added to ref.pspell | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93703@lists.php.net to get a copy of this message | ||
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("\"",'"',$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.
----
Manual Page -- http://www.php.net/manual/en/ref.pspell.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55863
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55863&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55863&report=yes
Search -- http://master.php.net/manage/user-notes.php