PHP show_source() 函数
定义和用法
show_source() 函数对文件进行语法高亮显示。
本函数是 highlight_file() 的别名。
语法
show_source(filename,return)
参数 | 描述 |
---|---|
filename | 必需。要进行高亮处理的 PHP 文件的路径。 |
return | 可选。如果设置 true,则本函数返回高亮处理的代码。 |
说明
本函数通过使用 PHP 语法高亮程序中定义的颜色,输出或返回包含在 filename 中的代码的语法高亮版本。
许多服务器被配置为对带有 phps 后缀的文件进行自动高亮处理。例如,在查看 example.phps 时,将显示该文件被语法高亮显示的源代码。要启用该功能,请把下面这一行添加到 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 it. Otherwise, if successful, it returns true, 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.
Example
"test.php":
<html> <body> <?php show_source("test.php"); ?> </body> </html>
Output:
<html> <body> <?php show_source("test.php"); ?> </body> </html>
The results displayed 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>