PHP highlight_string()Functions

PHP Misc 参考手册PHP Misc Reference Manual

Examples

Highlight PHP syntax for a string:

<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>

The browser output of the above code is as follows:

Hello world! <?php phpinfo(); ?>

The HTML output of the above code is as follows (view source code):

<html>
<body>
<code>
<span style="color: #000000">Hello&nbsp;world!&nbsp;
<span style="color: #0000BB">&lt;?php&nbsp;phpinfo</span>
<span style="color: #0053A6">();&nbsp;</span>
<span style="color: #0000BB">?&gt;</span>
</span>
</code>
</body>
</html>

Run Example »

Definition and Usage

The highlight_string() function highlights PHP syntax for a string. The string is highlighted using HTML tags.

The colors used for highlighting can be set in the php.ini file or by calling the ini_set() function.


Syntax

highlight_string(string,return)

Parameter Description
string Required. Specifies the string to be highlighted.
return Optional. If this parameter is set to TRUE, the function will return the highlighted code as a string instead of outputting it directly. Default is FALSE.

Technical Details

Return value: Returns TRUE on success, or FALSE on failure.
PHP Version: 4+
Changelog: Added in PHP 4.2.0returnparameter.


PHP Misc 参考手册PHP Misc Reference Manual Other Extensions