source: show_source_.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

    
/////////////////////////////////////////////////////////////////////////////
    //
    //    show_source_.php

    
$sourceFile "show_source_.php";

    
ini_set"highlight.comment",    "#CC0000" );
    
ini_set"highlight.string",    "#EE8800" );
    
ini_set"highlight.default",    "#000066" );
    
ini_set"highlight.html",        "#0000CC" );
    
ini_set"highlight.keyword",    "#006600" );

    function 
SyntaxHighlight$source ) {
        
clearstatcache();
        
$html "source: ".$source."<br />\n";
        if ( 
file_exists$source ) ) {
            
$handle fopen$source"r" );
            
$size filesize$source );
            
$file fread$handle$size );
            
$code highlight_string$filetrue );
            
$code preg_replace'{([\w]+)(\s*</font><font\s+color="'.ini_get'highlight.keyword' ).'">|)(\s*\()}',
                
'<a target="_new" title="doc PHP $1" href="http://www.php.net/$1">$1</a>$2$3'$code );
            
$arrHTML explode"<br />"$code );
            
$count count$arrHTML );
            
//    prepare html...
            
$html .= "<br />\n";
            
$html .= "<table cellpadding='0' cellspacing='0' border='0'>\n<tr>\n";
            
$html .= "<td align='center' width='30' class='line'>";
            
//    line numbers...
            
for$i 1$i <= $count$i++ ) {
                
$html .= $i."<br />";
            }
            
$html .= "</td>\n<td align='left' nowrap>\n";
            
//    code lines...
            
foreach$arrHTML as $line ) {
                
$html .= $line."<br />\n";
            }
            
$html .= "</td>\n</tr>\n</table>\n";
            
fclose$handle );
        } else {
            
$html .= "error: file does not exist!<br />\n";
        }
        echo 
$html;
    }

    echo 
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
    echo 
"<html lang='de'>\n";
    echo 
"<head>\n";
    echo 
"<title>[ ".$sourceFile." ]</title>\n";
    echo 
"<style type='text/css'>\n";
    echo 
"<!--\n";
    echo 
"body { font-family: Courier; font-size: 11px; line-height: 1.5 }\n";
    echo 
"td { font-family: Courier; font-size: 11px; line-height: 1.5 }\n";
    echo 
"code { font-family: Courier; font-size: 11px; }\n";
    echo 
"A:link { font-family: Courier; color: #0066CC; font-size: 11px; text-decoration: none; }\n";
    echo 
"A:visited { font-family: Courier; color: #0066CC; font-size: 11px; text-decoration: none; }\n";
    echo 
"A:hover { font-family: Courier; color: #0066CC; font-size: 11px; text-decoration: underline; }\n";
    echo 
".line { font-family: Courier; color: #888888; font-size: 11px; }\n";
    echo 
"//-->\n";
    echo 
"</style>\n";
    echo 
"</head>\n";
    echo 
"<body bgcolor='#ffffff'>\n";

    
SyntaxHighlight$sourceFile );

    echo 
"</body>\n";
    echo 
"</html>\n";

?>