PHP highlight_string()Functions
Examples
Highlight PHP syntax for a string:
<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</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 world!
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #0053A6">(); </span>
<span style="color: #0000BB">?></span>
</span>
</code>
</body>
</html>
<body>
<code>
<span style="color: #000000">Hello world!
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #0053A6">(); </span>
<span style="color: #0000BB">?></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 Reference Manual Other Extensions