highlight_string

bool highlight_string(string code_snippet) 

Applies PHP syntax highlight to a string.

Returns:

TRUE on success; FALSE on failure

Description:

highlight_string() is used to apply PHP syntax highlighting to a string and then display it. The syntax highlighting is applied using HTML tags. The function returns TRUE on success and FALSE on failure.

The colors used for highlighting can be set in the php.ini file. They can also be set using the ini_set() function; see highlight_file() for an example.

Note:

The string passed should contain PHP code block start and end tags if it is to be properly highlighted; for example, 'printf ("%0.2d", 0x2)' will not be highlighted, while '<?php printf ("%0.2d", 0x2) ?>' will be highlighted.

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.