开发者

PHP spell checking tool

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 'anotho开发者_如何学Cr' 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜