Open In App

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:



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:

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






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

Output: Example 2: Save the given code using name geeks.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. 




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

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


Article Tags :