'); $errors = array(); $braces = 0; foreach ($tokens as $token) { if ($token == '{') $braces = $braces + 1; else if ($token == '}') $braces = $braces - 1; if ($braces < 0) { $errors[0]['name'] = 'Syntax error.'; break; } } if (empty($errors)) { if ($braces) $errors[0]['name'] = 'Unbalanced braces.'; } else if (!evalCode($code)) { $errors[0]['name'] = 'Syntax error.'; } if (empty($errors)) foreach ($disallowedExpressions as $disallowedExpression) { unset($matches); preg_match($disallowedExpression, $code, $matches); if ($matches) { $errors[0]['name'] = 'Execution operator / variable function name / variable variable name detected.'; break; } } if (empty($errors)) { unset($tokens[0]); unset($tokens[0]); array_pop($tokens); array_pop($tokens); $i = 0; foreach ($tokens as $key => $token) { $i++; if (is_array($token)) { $id = token_name($token[0]); switch ($id) { case ('T_STRING'): if (in_array(strtolower($token[1]), $allowedCalls) === false) { $errors[$i]['name'] = 'Illegal function: '.$token[1]; $errors[$i]['line'] = $token[2]; } break; default: if (in_array($id, $allowedTokens) === false) { $errors[$i]['name'] = 'Illegal token: '.$token[1]; $errors[$i]['line'] = $token[2]; } break; } } } } if (!empty($errors)) { return $errors; } } //错误提示 function htmlErrors($errors = null) { if ($errors) { $errorsHTML = "
"; $errorsHTML .= '内嵌脚本缺失,请添加该函数:'; $errorsHTML .= '
'; foreach ($errors as $error) { if ($error['line']) { $errorsHTML .= '
Line '.$error['line'].'
'; } $errorsHTML .= '
'.$error['name'].'
'; } $errorsHTML .= '
'; $errorsHTML .= "
\r\n"; echo $errorsHTML; } } ?>