show_source()
function outputs a file with PHP syntax highlighting. Syntax highlighting is achieved by using HTML tags.
The colors used for highlighting can be set in the php.ini file, or using the ini_set() function.
show_source()
is an alias for the highlight_file() function.
Note: When using this function, the entire file will be displayed - including passwords and any other sensitive information! Please be careful to use.
Use a test file ("test.php") to output files with PHP syntax highlighting:
< html > < body > <?php show_source ( "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 (please check the 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 >
Try it yourself
show_source ( filename , return )
parameter | describe |
---|---|
filename | Required. The path to the PHP file to be highlighted. |
Return |
Optional. If set to TRUE, this function returns the highlighted code as a string instead of printing it out. The default is FALSE. |
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
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.