highlight_string
(PHP 4, PHP 5)
highlight_string — Syntax highlighting of a string
说明
mixed highlight_string ( string $str [, bool $return = false ] )Outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP.
参数
- str
-
The PHP code to be highlighted. This should include the opening tag.
- return
-
Set this parameter to TRUE to make this function return the highlighted code.
返回值
If return is set to TRUE, returns the highlighted code as a string instead of printing it out. Otherwise, it will return TRUE on success, FALSE on failure.
更新日志
版本 | 说明 |
---|---|
4.2.0 | The return parameter was added. |
范例
Example #1 highlight_string() example
The above example will output (in PHP 4):
The above example will output (in PHP 5):
<?php
highlight_string('<?php phpinfo(); ?>');
?>
<code><font color="#000000">
<font color="#0000BB"><?php phpinfo</font><font color="#007700">(); </font><font color="#0000BB">?></font>
</font>
</code>
<code><span style="color: #000000">
<span style="color: #0000BB"><?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?></span>
</span>
</code>
注释
Note:
此函数使用其参数内部的输出缓冲,所以不能当作 ob_start() 的回调函数。
参见
- highlight_file() - Syntax highlighting of a file