PHP拼写检查工具

Bei*_*ier 4 php spell-checking

是否有这样的工具在PHP代码中的代码注释和字符串中发现语言/拼写错误?例如,

<?php
$myVar = "Hollo World";
//this is a code commont with spelling error
/*this is anothor wrong comment*/
?>
Run Code Online (Sandbox Code Playgroud)

如果我运行这样的工具,那么它会为我找到'Hollo','commont'和'anothor'拼写错误.

Pet*_*tai 12

看一下PHP函数pspell_check(),它是Pspell的一部分.

它需要Aspell库.

您可能还对Enchant感兴趣,EnchantEnchant Library的PHP绑定.它支持Aspell,用文档的话来说:

附魔步骤可以在所有拼写库之上提供统一性和一致性,并实现任何单个提供程序库中可能缺少的某些功能.


这是pspell_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"
Run Code Online (Sandbox Code Playgroud)

要检查整个文件中的拼写(例如程序中的所有代码和注释),您可以使用文件将文件转换为字符串,使用file()条带符号preg_replace(),将其分解为单词explode(),然后通过拼写检查运行它.


由于您的问题已被标记PHP,我认为您需要一个有PHP针对性的程序化解决方案; 然而,当然,PHP之外还有无数的拼写检查选项.


Tom*_*zyk 9

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