在线 PHP 语法检查器/验证器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5269530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Online PHP syntax checker / validator
提问by Web_Designer
Could someone refer me to an online PHP validator? It would be of much help.
有人可以将我推荐给在线 PHP 验证器吗?这会有很大帮助。
Thanks in advance!
提前致谢!
回答by Jacob
To expand on my comment.
扩展我的评论。
You can validate on the command line using php -l [filename]
, which does a syntax check only (lint). This will depend on your php.ini error settings, so you can edit you php.ini or set the error_reporting in the script.
您可以在命令行上使用 进行验证php -l [filename]
,它仅进行语法检查 (lint)。这将取决于您的 php.ini 错误设置,因此您可以编辑 php.ini 或在脚本中设置 error_reporting。
Here's an example of the output when run on a file containing:
这是在包含以下内容的文件上运行时的输出示例:
<?php
echo no quotes or semicolon
Results in:
结果是:
PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in badfile.php on line 2
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in badfile.php on line 2
Errors parsing badfile.php
I suggested you build your own validator.
我建议您构建自己的验证器。
A simple page that allows you to upload a php file. It takes the uploaded file runs it through php -l
and echos the output.
一个简单的页面,允许您上传 php 文件。它需要上传的文件运行它php -l
并回显输出。
Note: this is not a security risk it does not execute the file, just checks for syntax errors.
注意:这不是安全风险,它不执行文件,只是检查语法错误。
Here's a really basic example of creating your own:
这是创建自己的一个非常基本的示例:
<?php
if (isset($_FILES['file'])) {
echo '<pre>';
passthru('php -l '.$_FILES['file']['tmp_name']);
echo '</pre>';
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
</form>
回答by Mukesh Chapagain
I found this for online php validation:-
我发现这个用于在线 php 验证:-
http://www.icosaedro.it/phplint/phplint-on-line.html
http://www.icosaedro.it/phplint/phplint-on-line.html
Hope this helps.
希望这可以帮助。
回答by Mario Lurig
Here's one more for you that not only performs the php -l
check for you, but also does some secondary analysis for mistakes that would not be considered invalid (e.g. declaring a variable with a double equal sign).
这里还有一个给你的,它不仅为你执行php -l
检查,而且还对不会被视为无效的错误进行一些二次分析(例如,声明一个带有双等号的变量)。
回答by Flipper
Here is a similar question to yours. (Practically the same.)
这是一个与您类似的问题。(实际上是一样的。)
What ways are there to validate PHP code?
Edit
编辑
The top answer there suggest this resource:
那里的最佳答案建议使用此资源:
http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v4/syntax-check.php
http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v4/syntax-check.php
回答by StarsSky
回答by Mark Gavagan
http://phpcodechecker.com/performs syntax check and a custom check for common errors.
http://phpcodechecker.com/执行语法检查和常见错误的自定义检查。
I'm a novice, but it helped me.
我是新手,但它帮助了我。
回答by Rohitashv Singhal
Here is also a good and simple site to check your php codes and share your code with fiends :
这里也是一个很好的简单站点,可以检查您的 php 代码并与朋友分享您的代码:
回答by mutewitness
In case you're interested, an offline checker that does complicated type analysis: http://strongphp.orgIt is notonline however.
如果您有兴趣,可以使用一个进行复杂类型分析的离线检查器:http: //strongphp.org但是 它不在线。