PHP highlight_file() Function
Example
PHP syntax highlighting of a test file ("test.php"):
The browser output of the above code is as follows (depending on the contents of the file):
The HTML output of the above code is as follows (view source):
echo ("test.php");
?>
Run Example »
Definition and Usage
The highlight_file() function performs PHP syntax highlighting on a file. The syntax is highlighted using HTML tags.
**Tip:** The colors used for highlighting can be set in the php.ini file or by calling the ini_set() function.
**Note:** When using this function, the entire file is displayed, including passwords and other sensitive information!
Syntax
highlight_file(
filename,return
)
| Parameters | Description |
|---|---|
| filename | Required. Specifies the file to display. |
| return | Optional. If set to TRUE, this function returns the highlighted code as a string instead of outputting it directly. Default is FALSE. |
Technical Details
| Return Value: | If both the return If the parameter is set to TRUE, this function returns the highlighted code as a string instead of outputting it directly. Otherwise, it returns TRUE on success and FALSE on failure. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | Since PHP 4.2.1 this function is also affected by safe_mode and open_basedir. However, safe_mode was removed in PHP 5.4. |
在 PHP 4.2.0 中新增了 return 参数。 |
PHP Misc Reference Manual