note 48577 added to function.pspell-suggest
| From: | andoryuusama at gmail dot com | Date: | Thu, 30 Dec 2004 21:37:11 +0000 |
| Subject: | note 48577 added to function.pspell-suggest | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82484@lists.php.net to get a copy of this message | ||
To get a more meaningful "did you mean", I use metaphones on the suggestion list, this
helps to insure that the word is one that "sounds" closer to the word spelled wrong.
<?php
function spellcheck ( $string ) {
$words = split(' ',$string);
$misspelled = $return = array();
pspell_config_create("en",PSPELL_NORMAL);
$int = pspell_new('en');
foreach ($words as $value) {
$check = preg_split('/[\W]+?/',$value);
if (($check[1] != '') and (strpos("'",$value) > 0) ) {$check[0] =
$value;}
if (($check[0] + 1 == 1) and (!pspell_check($int, $check[0]) )) {
$res .= '<SPAN class="misspelled" style="color:#FF0000;
font-weight:bold;">' . $value . ' </SPAN> ';
$poss = pspell_suggest($int,$value);
$orig = metaphone($value);
foreach ($poss as $suggested)
{
$ranked[metaphone($suggested)] = $suggested;
}
if ($ranked[$orig] <> '') {$poss[1] = $ranked[$orig];}
$res2 .= '<SPAN style="color:#CC8800; font-weight:bold">' . $poss[1]
. ' </SPAN> ';
} else {
$res .= $value . ' ';
$res2 .= $value . ' ';
}
}
$n[1] = $res;
$n[2] = $res2;
return $n;
}
?>
this helps to correct for the fact that pspell_suggest's first idea of a replacement is just
the first in the alphabet.
----
Manual Page -- http://www.php.net/manual/en/function.pspell-suggest.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48577
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48577&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48577&report=yes
Search -- http://master.php.net/manage/user-notes.php