highlight_string
字符串的语法高亮
highlight_string()
函数输出带有 PHP 语法高亮的字符串。字符串通过使用 HTML 标签进行高亮。
用于语法高亮的颜色可以在 php.ini 文件中设置,或者使用 ini_set() 函数来设置。
输出带有 PHP 语法高亮的字符串:
<html> <body> <?php highlight_string("Hello world! <?php phpinfo(); ?>"); ?> </body> </html>
输出:
Hello world! <?php phpinfo(); ?>
在浏览器中查看的结果类似这样:
<html> <body> <code> <span style="color: #000000">Hello world! <span style="color: #0000BB"><?php phpinfo</span> <span style="color: #007700">(); </span> <span style="color: #0000BB">?></span> </span> </code> </body> </html>
亲自试一试
highlight_string(string,return)
参数 | 描述 |
---|---|
string | 必需。指定要高亮的字符串。 |
return |
可选。如果设置为 TRUE,此函数将返回高亮的代码作为字符串,而不是将其打印出来。 默认是 FALSE。 |
本函数通过使用 PHP 语法高亮程序中定义的颜色,输出或返回给定的 PHP 代码的语法高亮版本。
如果 return 参数被设置为 true,那么该函数会以字符串返回被高亮处理的代码,而不是输出它们。否则,若成功,则返回 true,失败则返回 false。