Friday, October 24, 2025
HomeLanguagesPHP | show_source() Function

PHP | show_source() Function

The show_source() function is an inbuilt function in PHP which is used to return a file with the PHP syntax highlighted. The syntax is highlighted by using HTML tags.

Syntax:

show_source( $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 display.
  • $return: It is optional 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: If it is set to TRUE then it returns the highlighted code as string. It will return TRUE on success or return FALSE on failure.

Note:

  • This function is available for PHP 4.0.0 and newer version.
  • The color 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.

Below programs illustrate the show_source() function in PHP:

Program 1: Below program save the file using file name show_source.php




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


Output:
image

Program 2: Below program save the file using file name source_code.php




<?php
  
// Loading XML document to $user
$user = <<<XML
<user>
    <username>Geeks123</username>
    <name>neveropen</name>
    <phone>+91-XXXXXXXXXX</phone>
    <detail font-color="blue" font-size="24px">
        Noida, India
    </detail>
</user>
XML;
  
// Loading string as simple xml object
  
$xml = simplexml_load_string($user);
  
// Printing children element
foreach($xml->children() as $child) {
    echo "child node:" . $child . "</br>";
}
  
?>


main.php




<!DOCTYPE html>
<html>
<body>
<?php
show_source("source_code.php");
?>
</body>
</html>


Output:

Reference: https://www.php.net/manual/en/function.show-source.php

Last Updated :
03 Jul, 2019
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS