检查 PHP 语法错误? [英] Check for PHP Syntax errors?
问题描述
好吧,我在这里遇到了一点泡菜.我需要检查一些 PHP 的语法错误.我注意到这一点需要从命令行运行:
Well, I have run into a bit of a pickle here. I am needing to check some PHP for syntax errors. I noticed this bit that needs to run from the commandline:
php -l somefile.php
但是,有没有办法从 PHP 文件本身运行它?我一直在寻找并认为我可以使用 parse_str
函数以某种方式通过将其输入 $_GET 来完成此操作,但不太明白这是如何工作的.
However, is there a way to run this from within a PHP file itself? I've been looking and have think that I can use parse_str
function somehow to accomplish this by entering it into a $_GET, but can't quite understand how this works.
别人告诉我使用 token_get_all()
php 函数来确定这一点.
Someone else told me to use token_get_all()
php function to determine this.
但我不知道如何用任何方法来做到这一点?这里的任何人都可以给我一些示例代码以开始使用吗??我不认为使用 eval()
是要走的路,虽然我有一个 eval($code)
工作,但不认为我应该运行脚本如果有 PHP 语法错误.
But I can't figure out how to do this with any approach? Can anyone here give me some sample code to get started perhaps?? I don't think using eval()
is the way to go, although I had an eval($code)
working, but don't think I should run the script if there are PHP syntax errors.
非常感谢您对此的任何帮助,一如既往!
Any help on this is greatly appreciated, as always!
推荐答案
你可以像这样简单地执行 shell_exec()
:
You could simply do shell_exec()
like this:
$output = shell_exec('php -l /path/to/filename.php');
这会在字符串 $output
中为您提供命令行操作的输出.
This gives you the output of the command line operation in the string $output
.
这篇关于检查 PHP 语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!