highlight_file()

highlight_file() — Syntax highlighting of a file.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Prints out or returns a syntax highlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP.

Signature

highlight_file(string $filename, bool $return = false): string|bool

Parameters

ParameterTypeWhat it takes
$filenamestringPath to the PHP file to be highlighted.
$returnboolSet this parameter to true to make this function return the highlighted code.

Return value

If return is set to true, returns the highlighted code as a string instead of printing it out. Otherwise, it will return true on success, false on failure.

Example

The PHP manual ships no example for highlight_file(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.3.0The resulting HTML has changed.

See also

highlight_string()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page highlight_file() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.