While working on an earlier post, I needed to find a way to display a PHP module on a web page without having it executed. I knew this was fairly simple and involved the
.phps file extension, but I hadn’t done it before. A quick search of the PHP site pointed me to the highlight_file function. About halfway down the page there is a blurb about the MIME type that I needed. It turns out that my web hosting service already has this enabled, so all I needed to do was get a
.phps extension on my file. I did it the easy way, with a softlink:
ln -s myfile.php myfile.phps
For those who don’t know Unix, this effectively creates another name for the same file, which is exactly what I want. This leaves the original
.php alone, so that it can be run by the web server. But is also allows me to post the code on the web, using the
.phps “file” which the web server will display instead of executing. The elegance of this solution is that if/when I modify the original code, I won’t have to make any changes to the displayable code because there is really only one file (with two distinct names).