views:

51

answers:

4

Is there such a tool that finds language/spelling errors in code comment and strings in PHP code? for example,

<?php
$myVar = "Hollo World";
//this is a code commont with spelling error
/*this is anothor wrong comment*/
?>

If I run such a tool, then it will find 'Hollo', 'commont', and 'anothor' spelling errors for me.

Thanks for any suggestion.

A: 

You can use Microsoft Word from Microsoft Office for it, this is not common programming related problem.

Svisstack
A: 

This depends a lot on the kind of editor you use and what tools you have at your disposal on your development machine (is it linux, do you have the aspell libraries, do you use eclipse, etc).

ikanobori
+5  A: 

IDEs such as Eclipse or NetBeans would do the spell checking themselves, you need only to enable such features.

Tomasz Kowalczyk
+1 for NetBeans. [Coda](http://www.panic.com/coda/) for Mac also spell checks comments and string literals.
Josh
+1  A: 

Take a look at the PHP function pspell_check() which is part of Pspell.

It requires the Aspell library.

You might also be interested in Enchant, the PHP binding for the Enchant Library. It supports Aspell, and in the words of the documentation:

Enchant steps in to provide uniformity and conformity on top of all spelling libraries, and implement certain features that may be lacking in any individual provider library.


Here's a pspell_check() example from the documentation. First you link to the appropriate dictionary, then you perform the spell check:

<?php
$pspell_link = pspell_new("en");

if (pspell_check($pspell_link, "testt")) 
{
    echo "This is a valid spelling";
} else 
{
    echo "Sorry, wrong spelling";
}
?>

// Output is "Sorry, wrong spelling"

To check spelling in an entire file (like all code and comments in a program), you could transform the file to a string using file(), strip punctuation with preg_replace(), break it into words with explode(), and run it through the spell check.


Since your question is tagged PHP, I assume you would like a PHP oriented programmatic solution; however, there are, of course, myriads of spell check options outside of PHP as well.

Peter Ajtai