Perform PHP syntax highlighting on the test file ("test.php"):
<html><body><?phphighlight_file("test.php");?></body></html>The browser output for the above code is as follows (depending on what is 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"><html><br /><body><br /><span style="color: #0000BB"><? php<br /></span><span style="color: #007700">echo (</span><span style="color: #DD0000">"test.php"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?><br /></span></body><br /></html></span></code></body></html>The highlight_file() function performs PHP syntax highlighting on files. Syntax highlighting is done using HTML tags.
Tip: The color used for highlighting can be set through 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!
highlight_file( filename,return )
parameter | describe |
---|---|
filename | Required. Specifies the files to be displayed. |
return | Optional. If this parameter is set to TRUE, the function returns the highlighted code as a string instead of outputting it directly. The default is FALSE. |
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, TRUE is returned on success and FALSE on failure. |
---|---|
PHP version: | 4+ |
Update log: | As of 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. |