简体   繁体   English

PHP拼写检查工具

[英]PHP spell checking tool

Is there such a tool that finds language/spelling errors in code comment and strings in PHP code? 是否有这样的工具在PHP代码中的代码注释和字符串中发现语言/拼写错误? 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. 如果我运行这样的工具,那么它会为我找到'Hollo','commont'和'anothor'拼写错误。

Take a look at the PHP function pspell_check() which is part of Pspell . 看一下PHP函数pspell_check() ,它是Pspell的一部分。

It requires the Aspell library . 它需要Aspell库

You might also be interested in Enchant , the PHP binding for the Enchant Library . 您可能还对Enchant感兴趣, EnchantEnchant Library的PHP绑定。 It supports Aspell, and in the words of the documentation: 它支持Aspell,用文档的话来说:

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. 这是文档中的pspell_check()示例。 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. 要检查整个文件中的拼写(如程序中的所有代码和注释),您可以使用file()将文件转换为字符串,使用preg_replace()删除标点,使用explode()将其分解为单词,然后运行它通过拼写检查。


Since your question is tagged PHP , I assume you would like a PHP oriented programmatic solution; 由于你的问题被标记为PHP ,我假设你想要一个面向PHP的程序化解决方案; however, there are, of course, myriads of spell check options outside of PHP as well. 然而,当然,PHP之外还有无数的拼写检查选项。

Eclipse或NetBeans等IDE会自行进行拼写检查,您只需启用此类功能即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM