This little code returns the file formatted as an array, line by line. You are free to choose which lines to display, and/or to add the line numbers in front of them. Index 0 = Line 1
<?php
function highlightArray($file) {
$cssRegexp = '/\<span style=\"([^\"]+)\"\>/';
$highlitedFile = highlight_file($file, true);
$code = substr($highlitedFile, 36, -15);
$globCss = preg_match($cssRegexp, substr($highlitedFile, 0, 36), $matche);
$globCss = $matche[1];
$array = explode('<br />', $code);
$lastCss = null;
$lines = array_map(function($line) use (&$lastCss, $globCss) {
if(preg_match('/^( )*$/',$line)) $line = ' ';
if(!empty($lastCss)) $line = '<span style="'.$lastCss .'">'. $line;
$diff = substr_count($line, '<span') - substr_count($line, '</span');
if($diff > 0) {
$line .= str_repeat('</span>', $diff);
$lastCss = preg_match_all('/\<span style=\"([^\"]+)\"\>/', $line, $matches);
$lastCss = array_pop($matches[1]);
} else {
$lastCss = NULL;
}
return "<span style=\"$globCss\">$line</span>";
}, $array);
return $lines;
}
?>