php语法检查方法——命令行模式和代码形式

1. 命令行形式

php -l /path/to/file.php

2. php代码形式

function php_syntax_check($file){
    $code = file_get_contents($file);
    $code = preg_replace("/^[sxefxbbxbf]*<?php/is", "", $code);
    $code = trim(preg_replace("/?>s*$/is", "", $code));
    $code = 'return 1;' . $code;
    if(@eval($code)){
        echo "No syntax error";
    } else {
        echo 'File "',$file,'" has syntax error';
    }
}
php_syntax_check("/path/to/file.php");
原文地址:https://www.cnblogs.com/uniqid/p/5956537.html