display contents of a PHP file with apache/php

Posted on 2007-10-17
Last Modified: 2008-01-09
Hi guys,

I want to display the contents of a PHP file with the proper syntax hi-lightning, as you view it in VIM, without executing its contents. I'm sure that I've seen this on apache/php documentation but can't remember were.
Question by:SHEEP
    LVL 24

    Expert Comment

    You can rename the file *.phps. As long as your webserver has the appropriate type setup (most do), your file will be displayed with syntax highlighting.
    LVL 20

    Expert Comment

    If your server doesnt have the correct setup or you dont want to change the extension you can use



    highlight_string() for highlighting just a part of the code

    LVL 1

    Author Comment

    Cheers steelseth12 but ain't there a way to do it with any file type, like sh, pl, reg, etc?
    LVL 20

    Accepted Solution

    highlight_file() is a php function so it needs to pass thought the php parser.

    highlight_file() can read any file regardless of its extension.

    If you want php the parse files other than the default you will need to add the doc type to the httpd.conf


    AddType application/x-httpd-php .pl
    LVL 20

    Expert Comment

    note: if you are you are going to get into that ... you might as well do

    AddType application/x-httpd-php-source .pl

    so you will not need to run the highlight_file() function

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now