PHP show_source() function

Definition and Usage

show_source() function to highlight the syntax of the file.

This function is highlight_file() alias.

Syntax

show_source(filename,return)
Parameters Description
filename Required. The path to the PHP file to be highlighted.
return Optional. If set to true, this function returns the highlighted code.

Description

This function outputs or returns the code included in filename version.

many servers are configured to highlight the syntax of the code in phps to automatically highlight files with the suffix. For example, when viewing example.phps, the source code of the file will be displayed with syntax highlighting. To enable this feature, add the following line to httpd.conf:

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

Return Value

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

Tips and Comments

Warning:It should be noted that when using the show_source() function, do not inadvertently disclose sensitive information such as passwords or other types of sensitive information, otherwise potential security risks may arise.

Examples

"test.php":

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

Output:

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

The results viewed in the browser are similar to this:

<html>
<body>
<code>
<span style="color: #000000"><html>
<br />
<body>
<br />
<span style="color: #0000BB"><?php
<br />show_source</span>
<span style="color: #007700">(</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>