PHP syntax highlighting for strings:
<html><body><?phphighlight_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: #007700">(); </span><span style="color: #0000BB">?></span></span></code></body></html>The highlight_string() function performs PHP syntax highlighting on strings. Strings are highlighted using HTML tags.
The color used for highlighting can be set through the php.ini file or by calling the ini_set() function.
highlight_string( string,return )
| parameter | describe |
|---|---|
| string | Required. Specifies the string to be highlighted. |
| return | Optional. If this parameter is set to TRUE, the function returns the highlighted code as a string instead of outputting it directly. The default is FALSE. |
| Return value: | Returns TRUE if successful and FALSE if failed. |
|---|---|
| PHP version: | 4+ |
| Update log: | The return parameter was added in PHP 4.2.0. |