PHP highlight_string() function
Definition and Usage
The highlight_string() function performs syntax highlighting on strings.
Syntax
highlight_string(string,return)
Parameter | Description |
---|---|
string | Required. The string to be highlighted. |
return | Optional. If set to true, this function returns the highlighted code. |
Description
This function outputs or returns the syntax highlighted version of the given PHP code by using the colors defined in the PHP syntax highlighting program.
Return Value
If return If the parameter is set to true, then this function will return the highlighted code as a string instead of outputting them. Otherwise, if successful, it returns true, and on failure, it returns false.
Example
<html> <body> <?php highlight_string("Hello world! <?php phpinfo(); ?>"); ?> </body> </html>
Output:
Hello world! <?php phpinfo();?>
The result viewed in the browser is similar to this:
<html> <body> <code> <span style="color: #000000">Hello world! </span> <span style="color: #0000BB"><?php phpinfo</span> <span style="color: #007700">();</span> <span style="color: #0000BB">?></span> </span> </code> </body> </html>