2 ////////////////////////////////////////////////////////////////////////////////
4 // phpcode: Displays or returns an HTML'ized version of a php file
6 ////////////////////////////////////////////////////////////////////////////////
7 function phpcode ($file, $funclink = true, $return = false) {
8 $data = @highlight_file ($file, true)
9 or die ("Unable to open file $file");
12 $data = explode ('<br />', $data);
13 $start = '<span style="color: #aaa;">';
19 foreach ($data as $line) {
23 } elseif ($i < 1000) {
24 $nbr = " $i";
26 $nbr = " $i";
28 $nbr = " $i";
30 $text .= sprintf("%s %s:%s %s<br>\n",
31 $start, $nbr, $end, str_replace("\n", '', $line));
35 // replace <code><span>... with <pre><span>... to justify numbers
36 $html_col = ini_get('highlight.html');
37 $text = preg_replace("/(<code><span style=\"color: $html_col\">)?/",
39 $text = preg_replace("/(<\/span><\/code>)?/",
41 $text = "<font family=fixed><span style=\"color: $html_col\">".$text."</span></font>";
43 // Wrap with div class=code
44 $text = '<div class="code">' . $text . '</div>';
45 // Optional function linking
46 if ($funclink === true) {
47 $keyword_col = ini_get('highlight.keyword');
48 $manual = 'http://www.php.net/function.';
50 // Match a highlighted keyword
51 '~([\w_]+)(\s*</font>)'.
52 // Followed by a bracket
53 '(\s*<font\s+color="' . $keyword_col . '">\s*\()~m',
54 // Replace with a link to the manual
55 '<a href="' . $manual . '$1">$1</a>$2$3', $text);
59 if ($return === false) {