Example 1. Creating a source highlighting URL
To setup a URL that can code hightlight any script that you pass to
it, we will make use of the "ForceType" directive in
Apache to generate a nice URL pattern, and use the
function highlight_file() to show a nice looking
code list.
In your httpd.conf you can add the following:
And then make a file named "source" and put it in your
web root directory.
<HTML>
<HEAD>
<TITLE>Source Display</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<?php
$script = getenv ("PATH_TRANSLATED");
if(!$script) {
echo "<BR><B>ERROR: Script Name needed</B><BR>";
} else {
if (ereg("(\.php|\.inc)$",$script)) {
echo "<H1>Source of: $PATH_INFO</H1>\n<HR>\n";
highlight_file($script);
} else {
echo "<H1>ERROR: Only PHP or include script names are allowed</H1>";
}
}
echo "<HR>Processed: ".date("Y/M/d H:i:s",time());
?>
</BODY>
</HTML>
|
Then you can use an URL like the one below to display a colorized
version of a script located in "/path/to/script.php"
in your web site.