Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » PHP » Simple function for PHP syntax highlighting

Simple function for PHP syntax highlighting

05/21/2011 by Dux   -   not rated

This little function uses the PHP syntax highlighting displaying the result in a table with line numbers.
Hard to do simplest. You can add CSS.
This function is used by solucior.com

source code



 
<?php
function tabcode($txt) {
   
$txt = str_replace(array("\t", "\r\n", "\r"), array("        ", "\n", "\n"), $txt);
   
$txt = highlight_string(''.$txt, true);
   
$txt = ereg_replace('(<?php )+', '', $txt);
   
$tab = explode("<br />", $txt);
   foreach (
$tab as $key => $line) {
       if (
$bg != '#fff') $bg = '#fff'; else $bg = '#F5F5F5';
       
$code .= '<tr><td>'.($key+1).'</td><td style="background:'.$bg.'">'.$line.'</td></tr>';
   }
   return
'<table cellspacing="0" cellpadding="0">'.$code.'</table>';
}
?>
Rate this code     |     Copied : 21x

Comments for Simple function for PHP syntax highlighting

No comment
Add a comment Nickname
ZOOM