(PHP 4 >= 4.0.0)
highlight_file -- Syntax highlighting of a fileThe highlight_file() function prints out a syntax higlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP. Returns TRUE on success, FALSE on failure.
Note: Care should be taken when using the show_source() and highlight_file() functions to make sure that you do not inadvertently reveal sensitive information such as passwords or any other type of information that might create a potential security risk.
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.
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.
|
Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it - for example - in a string.
See also highlight_string(), show_source().