note 90229 modified in function.highlight-file by danbrown

From: Date: Sat, 11 Apr 2009 15:13:19 +0000
Subject: note 90229 modified in function.highlight-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153085@lists.php.net to get a copy of this message
I get linenumbers this way... cause I don't like tables :p <?php function highlight_linenumbers ($page) { // remove <code> and global <span> $code = highlight_file($page, true) ,36,-15); echo '<ol style="font-family:monospace; color:', ini_get('highlight.{default}') , ';">'; $arr = explode('<br />', $code); foreach( $arr as $line ) { // removing newline $line = substr($line, 0, -1); //empty lines if( preg_match('^(&nbsp;)*$',$line) ) $line = '&nbsp;'; // add colour from the previous line if( !empty($last_colour) ) $s = '<span style="color:'.$last_colour .'">'. $s; // Supposing we open more spans on a line than closing... let's do this properly // We have at most one currently opened span if( substr_count($line, '<span') - substr_count($line, '</span') > 0 ) { $line .= '</span>'; // Grab colour to report it on next line $last_colour = explode('<span ',$line); $last_colour = $last_colour[count($last_colour)-1]; $last_colour = substr($last_colour,strpos($last_colour,'#'),7); else $last_colour = NULL; echo '<li>',$line,"</li>\r"; } echo '</ol>'; } ?> --was-- I get linenumbers this way... cause I don't like tables :p <? function highlight_linenumbers ($page) { // remove <code> and global <span> $code = highlight_file($page, true) ,36,-15); echo '<ol style="font-family:monospace; color:', ini_get('highlight.{default}') , ';">'; $arr = explode('<br />', $code); foreach( $arr as $line ) { // removing newline $line = substr($line, 0, -1); //empty lines if( preg_match('^(&nbsp;)*$',$line) ) $line = '&nbsp;'; // add colour from the previous line if( !empty($last_colour) ) $s = '<span style="color:'.$last_colour .'">'. $s; // Supposing we open more spans on a line than closing... let's do this properly // We have at most one currently opened span if( substr_count($line, '<span') - substr_count($line, '</span') > 0 ) { $line .= '</span>'; // Grab colour to report it on next line $last_colour = explode('<span ',$line); $last_colour = $last_colour[count($last_colour)-1]; $last_colour = substr($last_colour,strpos($last_colour,'#'),7); else $last_colour = NULL; echo '<li>',$line,"</li>\r"; } echo '</ol>'; } ?> http://php.net/manual/en/function.highlight-file.php

« previous php.notes (#153085) next »