Please wait while we load your page...


PHP Manual :: highlight_string

highlight_file || ignore_user_abort || Misc. Functions || PHP Manual

(PHP 4, PHP 5, PHP 7)

highlight_stringSyntax highlighting of a string


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.



The PHP code to be highlighted. This should include the opening tag.


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.


Example #1 highlight_string() example

('<?php phpinfo(); ?>');

The above example will output (in PHP 4):

<code><font color="#000000">
<font color="#0000BB">&lt;?php phpinfo</font><font color="#007700">(); </font><font color="#0000BB">?&gt;</font>

The above example will output (in PHP 5):

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?&gt;</span>



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 || ignore_user_abort || Misc. Functions || PHP Manual
Live Chat Not Available