Current Location: Home> Function Categories> highlight_file

highlight_file

Syntax highlighting a file
Name:highlight_file
Category:Miscellaneous
Programming Language:php
One-line Description:Syntax highlighting of the file.

Definition and usage

highlight_file() function outputs a file with PHP syntax highlighting. Syntax highlighting is achieved by using HTML tags.

Tip: The colors used for syntax highlighting can be set in the php.ini file, or use the ini_set() function to set.

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

Example

Use a test file ("test.php") to output files with PHP syntax highlighting:

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

The browser output of the above code may be (depending on what is in the file):

 < html >
< body >
<?php
"color: #007700" > echo "COLOR: #007700" > ( "COLOR: #dd0000" > "test.php" "COLOR: #007700" > ) ;
"COLOR: #0000bb" > ?>
</ body >
</ html >

The HTML output of the above code may be (see the source code):

 < html >
< body >
< code >
< span style = " color : #000000 " >
< html >
< body >
< span style = " color : #0000BB " > <? php < / span >
< span style = "color: #007700" > echo ( < / span > < span style = "color: #DD0000" > "test.php" < / span >
< span style = "color: #007700" > ) ; < / span >
< span style = "color: #0000BB" > ?> </ span >
</ body >
</ html >
</ span >
</ code >
</ body >
</ html >

grammar

 highlight_file ( filename , return )
parameter describe
filename Required. Specifies the file to highlight.
Return

Optional. If set to TRUE, this function returns the highlighted code as a string instead of printing it out.

The default is FALSE.

illustrate

This function outputs or returns a syntax highlighting version of the code contained in filename by using the color defined in the PHP syntax highlighting program.

Many servers are configured to automatically highlight files with phps suffix. For example, when viewing example.phps, the source code that the file is syntactically highlighted is displayed. To enable this feature, add the following line to httpd.conf :

 AddType application/x-httpd-php-source .phps

Return value

If the return parameter is set to true, the function returns the highlighted code instead of outputting them. Otherwise, if successful, it will return true, and if it fails, it will return false.

Similar Functions