Saturday, November 22, 2025
HomeLanguagesPHP | highlight_file() Function

PHP | highlight_file() Function

The highlight_file() function is an inbuilt function in PHP which is used to highlight the syntax of file. The syntax is highlighted by using HTML tags. Syntax:

highlight_file( $filename, $return )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $filename: It is required parameter. It specifies the file whose content to be displayed.
  • $return: It is optional and boolean parameter. Its default value is FALSE. If it is set to TRUE, instead of printing it out, this function will return the highlighted code as a string.

Return Value: It returns TRUE on success, or returns FALSE on failure. If $return is set to TRUE, it will return the highlighted code as a string. Note:

  • This function is available on PHP 4.0.0 and newer version.
  • The colors used for highlighting the PHP syntax can be set with the ini_set() function or in the php.ini file.
  • With this function entire file will be displayed, that may include sensitive data like passwords etc.

Example 1: Save the given code using name server.php and run the program. 

php




<!DOCTYPE html>
<html>
 
<body>
    <?php
        highlight_file("neveropen.php");
    ?>
</body>
 
</html>


Output: Example 2: Save the given code using name neveropen.php. 

php




<?php
 
// Loading XML document to $user
$user = <<<XML
<user>
    <username>Username</username>
    <name>Firstname Lastname</name>
    <phone>+91-9876543210</phone>
    <detail font-color="blue" font="awesome-fonts"
            font-size="24px">
        Noida, India
    </detail>
</user>
XML;
 
// Loading the string as simple xml object
$xml = simplexml_load_string($user);
 
// Print the children
foreach($xml->children() as $child) {
    echo "child node:".$child."</br>";
}
 
?>


Use the above filename in the below program to highlight the syntax. 

php




<!DOCTYPE html>
<html>
 
<body>
    <?php
        highlight_file("neveropen.php");
    ?>
</body>
 
</html>


Output: Reference: https://php.net/manual/en/function.highlight-file.php

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS