/** * Format a html output of an code fragment (seven lines before and after) around the give line of the given source file * * @version 1.0 * @author greg <*****@*****.**> * * @param string $filepath path to the source file * @param integer $lineno line number of the interesting line * @return string html formated string */ public static function fetchCodeFragment($filepath, $lineno) { if (!empty($filepath) && file_exists($filepath)) { $filecontent = file($filepath); $start = max($lineno - 7, 0); $end = min($lineno + 7, count($filecontent)); $line = ''; $fragment = ''; for ($loop = $start; $loop < $end; $loop++) { if (!empty($filecontent[$loop])) { $line = $filecontent[$loop]; $line = preg_replace('#\\n$#', '', $line); $line = PHPDS_backtrace::highlightString($line, $loop + 1); } if ($loop == $lineno - 1) { $line = '<span class="highlight-error">' . $line . '</span>'; } $fragment .= $line . "\n"; } return $fragment; } else { return null; } }
/** * Format a html output of an code fragment (seven lines before and after) around the give line of the given source file * * @version 1.0 * @author greg <*****@*****.**> * * @param string $filepath path to the source file * @param integer $lineno line number of the interesting line * @return string html formated string */ public static function fetchCodeFragment($filepath, $lineno) { if (!empty($filepath) && file_exists($filepath)) { $filecontent = file($filepath); $start = max($lineno - 7, 0); $end = min($lineno + 7, count($filecontent)); $line = ''; $fragment = '<div class="ui-state-default ui-corner-all"></div><div class="toggle">'; for ($loop = $start; $loop < $end; $loop++) { if (!empty($filecontent[$loop])) { $line = $filecontent[$loop]; $line = preg_replace('#\\n$#', '', $line); $line = PHPDS_backtrace::highlightString($line, $loop + 1); } if ($loop == $lineno - 1) { $line = '<span class="ui-state-highlight ui-corner-all">' . $line . '</span>'; } $fragment .= $line . '<br />' . "\n"; } $fragment .= '</div>'; return $fragment; } else { return '<p>Missing file...</p>'; } }