highlight_file() function in PHP


The highlight_file() function outputs a file with the PHP syntax highlighted.

Syntax

highlight_file(file, return)

Parameters

  • file − The file name to display.

  • return − If this parameter is set to true, this function will return the highlighted code as a string, instead of printing it out. default is false.

Return

The highlight_file() function returns the highlighted code as a string instead of printing it. Returns true on success, or false on failure, otherwise.

Example

The following is an example, wherein we are using a test file ("new.php") to output the file with the PHP syntax highlighted.

<html>
   <body>
      <?php
         highlight_file("new.php");
      ?>
   </body>
</html>

Output

The output of the browser.

<html>
   <body>
      <?php
         echo ("new.php");
      ?>
   <body>
<html>

Updated on: 30-Dec-2019

109 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements