有没有一种工具可以在PHP代码的注释和字符串中查找语言/拼写错误?例如,
<?php
$myVar = "Hollo World";
//this is a code commont with spelling error
/*this is anothor wrong comment*/
?>
如果我运行这样的工具,它将为我找到 'Hollo'、'commont' 和 'anothor' 的拼写错误。
有没有一种工具可以在PHP代码的注释和字符串中查找语言/拼写错误?例如,
<?php
$myVar = "Hollo World";
//this is a code commont with spelling error
/*this is anothor wrong comment*/
?>
请查看PHP函数pspell_check(),它是Pspell的一部分。
它需要使用Aspell库。
您可能还会对Enchant感兴趣,它是用于Enchant Library的PHP绑定。 它支持Aspell,并且在文档中说:
Enchant为所有拼写库提供统一性和一致性,并实现任何个体提供者库中可能缺少的某些功能。
这里是一个从文档中提取出来的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"
想要检查整个文件(例如程序中的所有代码和注释)的拼写,可以使用 file()
将文件转换为字符串,用 preg_replace()
去掉标点符号,用 explode()
将其分解成单词,并通过拼写检查进行检查。
由于你的问题标记了 PHP
,我假设你希望得到一个以 PHP
为导向的编程解决方案;但是,当然也有许多 PHP 以外的拼写检查选项。
像Eclipse或NetBeans这样的集成开发环境可以自行进行拼写检查,您只需要启用此类功能即可。