automatische-highlighter-voor-php-bestanden
Gesponsorde koppelingen
PHP script bestanden
.htaccess
highlighter.php
Code (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
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
<?php
$ready = false;
if (isset($_GET['file']))
{
$file = $_GET['file'];
$pathinfo = pathinfo($file);
$ext = $pathinfo['extension'];
$bname = $pathinfo['basename'];
if ($ext == 'php')
{
$file = 'upload/' . $file;
if (file_exists($file))
{
echo '<link rel="stylesheet" href="../highlighter.css" type="text/css" />' . "\n";
echo '<h1>Highlighter</h1>' . "\n";
echo '<h2>' . $bname . '</h2>' . "\n";
$highlighted = highlight_file($file, true);
$lines = explode('<br />', $highlighted);
echo '<table class="code">' . "\n";
echo '<tr>' . "\n";
echo '<td id="linenumbers">' . "\n";
foreach ($lines as $lineID => $line)
{
$spaces = strlen(count($lines)) - strlen($lineID + 1);
for ($i = 0; $i < $spaces; $i ++)
{
echo ' ';
}
echo $lineID + 1 . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '<td class="code">' . "\n";
foreach ($lines as $line)
{
echo $line . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '</tr>' . "\n";
echo '</table>' . "\n";
$ready = true;
}
}
}
if (!$ready)
{
echo 'Oops, er ging iets mis...';
}
?>
$ready = false;
if (isset($_GET['file']))
{
$file = $_GET['file'];
$pathinfo = pathinfo($file);
$ext = $pathinfo['extension'];
$bname = $pathinfo['basename'];
if ($ext == 'php')
{
$file = 'upload/' . $file;
if (file_exists($file))
{
echo '<link rel="stylesheet" href="../highlighter.css" type="text/css" />' . "\n";
echo '<h1>Highlighter</h1>' . "\n";
echo '<h2>' . $bname . '</h2>' . "\n";
$highlighted = highlight_file($file, true);
$lines = explode('<br />', $highlighted);
echo '<table class="code">' . "\n";
echo '<tr>' . "\n";
echo '<td id="linenumbers">' . "\n";
foreach ($lines as $lineID => $line)
{
$spaces = strlen(count($lines)) - strlen($lineID + 1);
for ($i = 0; $i < $spaces; $i ++)
{
echo ' ';
}
echo $lineID + 1 . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '<td class="code">' . "\n";
foreach ($lines as $line)
{
echo $line . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '</tr>' . "\n";
echo '</table>' . "\n";
$ready = true;
}
}
}
if (!$ready)
{
echo 'Oops, er ging iets mis...';
}
?>
highlighter.css
Code (php)
1
2
3
4
2
3
4
table.code .linenumbers, table.code .code, table.code { background-color: #F2F2F2; font-size: 9pt; font-family: "Courier New"; }
table.code { display: block; width: 500px; border: 10px solid #F2F2F2; border-bottom: 0px solid black; }
table.code .linenumbers { display: block; }
table.code .code { display: block; overflow: auto; }
table.code { display: block; width: 500px; border: 10px solid #F2F2F2; border-bottom: 0px solid black; }
table.code .linenumbers { display: block; }
table.code .code { display: block; overflow: auto; }