Easy Tutorial
❮ Func String Hebrevc Func Date Timezone Name From Abbr ❯

PHP highlight_file() Function

PHP Misc Reference Manual

Example

Highlight PHP syntax for a test file ("test.php"):

The browser output of the above code is as follows (depending on the content of the file):

The HTML output of the above code is as follows (view source):


Definition and Usage

The highlight_file() function highlights PHP syntax for a file. Syntax is highlighted using HTML tags.

Tip: The colors for highlighting can be set via the php.ini file or by calling the ini_set() function.

Note: When using this function, the entire file will be displayed, including passwords and other sensitive information!


Syntax

Parameter Description
filename Required. Specifies the file to be displayed.
return Optional. If this parameter is set to TRUE, the function will return the highlighted code as a string instead of outputting it directly. The default is FALSE.

Technical Details

Return Value: If the return parameter is set to TRUE, the function will return the highlighted code as a string instead of outputting it directly. Otherwise, it returns TRUE on success or FALSE on failure.
PHP Version: 4+
--- ---
Changelog: As of PHP 4.2.1, this function is also affected by safe_mode and open_basedir. However, safe_mode was removed in PHP 5.4. <br> <br>The return parameter was added in PHP 4.2.0.
--- ---
❮ Func String Hebrevc Func Date Timezone Name From Abbr ❯