// GeSHi class - http://qbnz.com/highlighter require_once('geshi/geshi.php'); // formats code from file $uri and highlights according to language $lang (using the GeSHi) function codify($htmlid,$uri,$lang,$line_numbers=true,$show_uri=true) { $dir = "/sourcecode/"; // default dir $lines = file(ABSDIR.$dir.$uri); // put lines of file into array $list = ($line_numbers)? 'ol' : 'ul'; // ordered or unordered list, whether or not you want line numbers $ret = "
<$list id=\"$htmlid\" class=\"code-list $lang\">"; if (!empty($lines)) { foreach ($lines as $line) { $line = rtrim($line); // get rid of whitespace at the end of each line $line = str_replace("\t"," ",$line); // replace tabs with 4 spaces $geshi = new GeSHi($line, $lang); // create GeSHi code highlighting object $geshi->enable_classes(); $line = $geshi->parse_code(); // apply GeSHi highlighting $line = preg_replace("@?pre.*>@U","",$line); // removes created by GeSHi $ret .= "