PHP highlight_file() 函数
定义和用法
highlight_file() 函数对文件进行语法高亮显示。
语法
highlight_file(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, cette fonction renverra le code traité en surbrillance, plutôt que de les afficher. Sinon, si elle réussit, elle renverra true, et en cas d'échec, false.
Avis et commentaires
Avertissement :Il est important de noter que lors de l'utilisation de la fonction highlight_file(), ne laissez pas échapper par négligence des informations sensibles telles que les mots de passe ou d'autres types d'informations, sinon il peut y avoir des risques de sécurité potentiels.
Exemple
"test.php":
<html> <body> <?php highlight_file("test.php"); ?> </body> </html>
Sortie :
<html> <body> <?php highlight_file("test.php"); ?> </body> </html>
Le résultat à voir dans le navigateur est similaire à cela :
<html> <body> <code> <span style="color: #000000"><html> <br /> <body> <br /> <span style="color: #0000BB"><?php <br />highlight_file</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>