PHP Function Reference

PHP show_source() Function



The PHP show_source() function is used to syntax highlighting of a file. It prints out or returns a syntax highlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP.

Many servers are configured to automatically highlight files with a phps extension. For example - example.phps when viewed will show the syntax highlighted source of the file. To enable this, add the below line to the httpd.conf:

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

This function is an alias of highlight_file() function.

Syntax

show_source(filename, return)

Parameters

filename Required. Specify the path to the PHP file to be highlighted.
return Required. If set to true it makes this function to return the highlighted code.

Return Value

If return is set to true, returns the highlighted code as a string instead of printing it out. Otherwise, it will return true on success, false on failure.

Example: show_source() example

In the example below the show_source() function is used to syntax highlighting of the file containing the given script.

<?php
//using the show_source() function
show_source(__FILE__);
?>

The output of the above code will be similar to (word wrapped for readability):

<code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br />show_source</span>
<span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span>
<span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
</span>
</code>

❮ PHP Miscellaneous Reference