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()?
            Asked
            
        
        
            Active
            
        
            Viewed 650 times
        
    1
            
            
        
        Jon Gauthier
        
- 25,202
 - 6
 - 63
 - 69
 
3 Answers
4
            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 :)
        Jon Gauthier
        
- 25,202
 - 6
 - 63
 - 69
 
- 
                    Any idea why the return() would be generating this warning? `PHP Notice: Only variables should be passed by reference` – Wonko the Sane Feb 12 '21 at 18:18
 
1
            
            
        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');
        Mickey Shine
        
- 12,187
 - 25
 - 96
 - 148
 
0
            
            
        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);
}
        Arvind Bhardwaj
        
- 5,231
 - 5
 - 35
 - 49