Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Spell Checker

  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Spell Checker

    Hi all I am just posting to see if someone could offer advice on where this script is going wrong. As the title implies it is supposed to be a basic spell checker, which informs the user what words, if any, they have gotten wrong. It is simple enough to follow but if anyone wants me to edit it with comments let me know, and I will be happy to oblige

    PHP Code:

    <?php 

        $usersEntry 
    $_POST[text];
        
    $words explode(" "$usersEntry);
        
    $dictionary fopen("dictionary/dictalt.txt""r");
        
    $words=preg_replace("/[^a-zA-Zs]/"""$words); 
        
    $content =     fgetc($dictionary);
        
            
    $wrong=0;
            
    $print="";
            
            foreach(
    $words as $word)
            {
            
            while (!
    feof($dictionary))
                {
                
                if (
    $word <= $content)
                    {
                    
    $content fgetc($dictionary);
                    }
                else
                    {
                    
    fclose($dictionary);
                    break;
                    }
                    
                }    
                if (
    $word == $content)
                    {
                    
    $print=$print.' '.$word.' ';
                    echo 
    $word." is correct";
                    }
                    else
                    {
                    
    $print=$print.' <span class="wrong">'.$word.'</span> ';
                    
    $wrong++;
                    }
                
            }
            
            
            echo
    '<h3>You made '.$wrong.' mistake(s) which are highlighted below</h3>
                 <p>'
    .$print.'</p>';
    I think it is a string comparison issue, I am aware of the strcmp function but even using that I could not get a positive comparison. The main problem is that it states every word is incorrect no matter what the spelling !

    I would appreciate any input/advice it is driving me crazy now

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Doing spell checking is a tough thing.

    Not sure what your final application is, but there is a free script
    that uses "pspell", which is normally enabled for PHP5 webhost users.

    Check this out and see if it might be a better way to do it.
    http://www.broken-notebook.com/spell_checker/index.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •