PHP Response
');
+
+ // Help user to find bad code line, if it gave an error
+
+ $errmsg_found = preg_match("`error.*:.* (?:in|File:) {$tmpfile}(?: on line|, Line:) (\d+)(?:$|, Message:)`i", implode("\n", $output), $matches);
+
+ if ($retval || $errmsg_found) {
+ /* Trap failed code - test both retval and output message
+ * Typical messages as at 2.3.x:
+ * "Parse error: syntax error, ERR_DETAILS in FILE on line NN"
+ * "PHP ERROR: Type: NN, File: FILE, Line: NN, Message: ERR_DETAILS"
+ */
+ $errline = $matches[1] - $lineno_correction;
+ $syntax_output = array();
+ $html = "";
+ exec("/usr/local/bin/php -s -d log_errors=off {$tmpfile}", $syntax_output);
+ // Lines 0, 2 and 3 are CSS wrapper for the syntax highlighted code which is at line 1
separated.
+ $syntax_output = explode("
", $syntax_output[1]);
+ $chars = strlen(count($syntax_output)) + 1;
+ for ($lineno = 1; $lineno < count($syntax_output) - $lineno_correction; $lineno++) {
+ if ($lineno == $errline) {
+ $lineno_prefix = ">>>" . str_repeat(' ', $chars - strlen($lineno));
+ } else {
+ $lineno_prefix = str_repeat(' ', ($chars + 3) - strlen($lineno));
+ }
+ $html .= "
" . $lineno_prefix . $lineno . ": {$syntax_output[$lineno + $lineno_correction - 1]}
\n";
+ }
+ echo sprintf(gettext('Line %s appears to have generated an error, and has been highlighted. The full response is below.
' .
+ 'Note that the line number in the full PHP response will be %s lines too large.'), $errline, $lineno_correction);
+ echo "
" . gettext("Error locator:") . "\n";
+ echo "
\n";
+ echo $html . "\n
\n";
+ }
$output = implode("\n", $output);
print("
" . htmlspecialchars($output) . "
");
// echo eval($_POST['txtPHPCommand']);
+
puts("
");
+
+ unlink($tmpfile);
?>
+