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

Valore di ritorno

Se return Se il parametro è impostato su true, la funzione restituirà il codice trattato con evidenziazione, invece di stamparlo. Altrimenti, se ha successo, restituirà true, altrimenti false.

Suggerimenti e commenti

Attenzione:Occorre notare che, durante l'uso della funzione show_source(), non rivelare informazioni sensibili come password o altri tipi di informazioni sensibili per evitare rischi di sicurezza potenziali.

Esempio

"test.php":

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

Output:

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

Il risultato visualizzato nel browser è simile a questo:

<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>