首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

highlight_string

(PHP 4, PHP 5, PHP 7)

highlight_string — Syntax highlighting of a string

Description

代码语言:javascript
复制
mixed highlight_string ( string $str [, bool $return = false ] )

Outputs or returns html markup for a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP.

Parameters

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.

Return Values

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.

Examples

Example #1 highlight_string() example

代码语言:javascript
复制
<?php
highlight_string('<?php?phpinfo();??>');
?>

The above example will output:

代码语言:javascript
复制
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?&gt;</span>
</span>
</code>

Notes

Note: When the return parameter is used, this function uses internal output buffering so it cannot be used inside an ob_start() callback function.

The HTML markup generated is subject to change.

See Also

  • highlight_file() - Syntax highlighting of a file

← highlight_file

ignore_user_abort →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com