Sorry for the double post, but I created a new method for defining the array.
I added check of typos. A user can only have 20 typos, otherwise the corrector will quit correcting it to reduce server load.
Code: Select all
//Spelling corrector START
function message_validate_spam($message)
{
if(isset($message) && $message != '')
{
$corr = array(
'accidentally', // 0
'accordion',
'acquaintance',
'acquaintance',
'aquire',
'acquit', // 5
'a lot',
'a lot',
'argument',
'a while',
'axle', // 10
'barbeque',
'believable',
'broccoli',
'cemetary',
'chauvinism', // 15
'chocolaty',
'colosseum',
'collectible',
'definite', // 20
'development',
'drunkenness',
'dumbbell',
'exercise',
'existence', // 25
'fiery',
'flabbergast',
'flotation',
'frustum',
'genius', //30
'grammar',
'handkerchief',
'harass',
'inadvertent',
'incidentally', //35
'indispensable',
);
$wrong = array(
'accidently', // 1
'accordian',
'acquaintence',
'aquaintance',
'acquire',
'aquit', // 5
'alot',
'allot',
'arguement',
'awhile',
'axel', // 10
'barbeque',
'believeable',
'brocolli',
'cemetery',
'chauvanism', // 15
'chocolatey',
'colliseum',
'collectable',
'definate', // 20
'developement',
'drunkeness',
'dumbell',
'excercise',
'existance', // 25
'firey',
'flabberghast',
'floatation',
'frustrum',
'genious', // 30
'grammer',
'hankerchief',
'harrass',
'inadvertant',
'incidently', // 35
'indispensible',
);
$l['corr'] = count($wrong) - 1;
$l['wrong'] = count($corr) - 1;
$typos = 0;
if($l['corr'] == $l['wrong'])
{
while($l['corr'] >= 0&& $typos <= 20)
{
while(strstr($message,$wrong[$l['corr']]) !== false)
{
$message = str_replace($wrong[$l['corr']], $corr[$l['corr']], $message);
}
while(strstr($message, ucwords($wrong[$l['corr']])) !== false)
{
$message = str_replace(ucwords($wrong[$l['corr']]), ucwords($corr[$l['corr']]), $message);
}
$l['corr'] = $l['corr'] - 1;
$typos = $typos + 1;
}
return $message;
}
else
{
return $message;
}
}
else
{
return $message;
}
}
//Spelling corrector END