views:

35

answers:

1

I'd like to use PHP's PSpell check function in my program. Is there an option somewhere for case-insensitive checking in pspell_check()?

A: 

I've found a way around the lack of an option for case insensitivity. PSpell's suggestion function seems to always return the correct capitalization of a mis-capitalized word as its first suggestion, so we can check for this if the initial spell check fails:

<?php

function pspell_icheck($dictionary_link, $word) {
  return ( pspell_check($dictionary_link, $word) ||
    strtolower(reset(pspell_suggest($dictionary_link, $word))) == strtolower($word) );
}

$dict = pspell_new('en');
$word = 'foo';
echo pspell_icheck($dict, $word);

?>

Works on PHP 5.3.2. Happy coding :)

hansengel