Current Location: Home> Function Categories> highlight_string

highlight_string

String syntax highlighting
Name:highlight_string
Category:Miscellaneous
Programming Language:php
One-line Description:Syntax highlighting of strings.

Definition and usage

highlight_string() function outputs a string with PHP syntax highlighting. Strings are highlighted by using HTML tags.

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

Example

Output strings with PHP syntax highlighting:

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

Output:

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

The results you view in the browser are similar to this:

 < 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 >

Try it yourself

grammar

 highlight_string ( string , return )
parameter describe
string Required. Specifies the string to highlight.
Return

Optional. If set to TRUE, this function returns the highlighted code as a string instead of printing it out.

The default is FALSE.

illustrate

This function outputs or returns a syntax highlighting version of the given PHP code by using the color defined in the program.

Return value

If the return parameter is set to true, the function returns the highlighted code as a string instead of outputting them. Otherwise, if successful, it will return true, and if it fails, it will return false.

Similar Functions
Popular Articles