简体   繁体   中英

Case-insensitive PSpell spell checking?

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() ?

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 :)

Try this patch http://code.google.com/p/patched-pspell/ . It enables you to set any options.

pspell_config_set($pspell_config, 'ignore-case', 'true');

There is an easy solution. Just do this:

$word = ucfirst($word); //Always capitalize to avoid case sensitive error
if (!pspell_check($dict, $word)) {
   $suggestions = pspell_suggest($dictionary, $word);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM