PHP highlight_file()Functions

PHP Misc 参考手册PHP Misc Reference Manual

Examples

Perform PHP syntax highlighting on the test file ("test.php"):

<html>
<body>
<?php
highlight_file("test.php");
?>
</body>
</html>

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

<html>
<body>
<?php
echo ("test.php");
?>
</body>
</html>

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

<html>
<body>
<code><span style="color: #000000">
&lt;html&gt;
<br />&lt;body&gt;
<br /><span style="color: #0000BB">&lt;?php
<br /></span><span style="color: #0053A6">echo&nbsp;(</span><span style="color: #DD0000">"test.php"</span><span style="color: #0053A6">);
<br /></span><span style="color: #0000BB">?&gt;
<br /></span>&lt;/body&gt;
<br />&lt;/html&gt;</span>
</code>
</body>
</html>

Run Example »

Definition and Usage

The highlight_file() function performs PHP syntax highlighting on a file. The syntax is highlighted by using HTML tags.

Tip:The colors used 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

highlight_file(filename,return)

Parameters 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. Default is FALSE.

Technical Details

Return Value: Ifreturnparameter is set to TRUE, the function will return the highlighted code as a string instead of outputting it directly. Otherwise, returns TRUE on success, or FALSE on failure.
PHP Version: 4+
Changelog: Since PHP 4.2.1, this function is now also affected by safe_mode and open_basedir. However, safe_mode was removed in PHP 5.4.

The return parameter was added in PHP 4.2.0.


PHP Misc 参考手册PHP Misc Reference Manual Other Extensions