PHP spell checking tool

余生长醉 提交于 2019-12-22 08:23:44

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/3688723/php-spell-checking-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!