企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# PHP highlight_string() 函数 ## 定义和用法 highlight_string() 函数对字符串进行语法高亮显示。 ### 语法 ``` highlight_string(string,return) ``` | 参数 | 描述 | | --- | --- | | string | 必需。要进行高亮处理的字符串。 | | return | 可选。如果设置 true,则本函数返回高亮处理的代码。 | ### 说明 本函数通过使用 PHP 语法高亮程序中定义的颜色,输出或返回给定的 PHP 代码的语法高亮版本。 ### 返回值 如果 _return_ 参数被设置为 true,那么该函数会以字符串返回被高亮处理的代码,而不是输出它们。否则,若成功,则返回 true,失败则返回 false。 ## 例子 ``` <html> <body> <?php highlight_string("Hello world! <?php phpinfo(); ?>"); ?> </body> </html> ``` 输出: ``` Hello world! <?php phpinfo();?> ``` 在浏览器中查看的结果类似这样: ``` <html> <body> <code> <span style="color: #000000">Hello&nbsp;world!&nbsp; <span style="color: #0000BB">&lt;?php&nbsp;phpinfo</span> <span style="color: #007700">();</span> <span style="color: #0000BB">?&gt;</span> </span> </code> </body> </html> ```