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
Valeur de retour
Si return Si le paramètre est réglé sur true, la fonction retournera le code traité en surbrillance plutôt que de les afficher. Sinon, si elle réussit, elle retournera true, en cas d'échec, false.
Avis et commentaires
Avertissement :Il convient de noter que lors de l'utilisation de la fonction show_source(), ne pas divulguer par négligence des informations sensibles telles que les mots de passe ou d'autres types d'informations, sinon cela peut entraîner des risques de sécurité potentiels.
Exemple
"test.php":
<html> <body> <?php show_source("test.php"); ?> </body> </html>
Sortie :
<html> <body> <?php show_source("test.php"); ?> </body> </html>
Le résultat affiché dans le navigateur est similaire à cela :
<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>