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.
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.
IDEs such as Eclipse or NetBeans would do the spell checking themselves, you need only to enable such features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With