Skip to content

Instantly share code, notes, and snippets.

@olzaragoza
Last active June 12, 2016 05:30
Show Gist options
  • Save olzaragoza/ff3582826721eda971535df2057e78fe to your computer and use it in GitHub Desktop.
Save olzaragoza/ff3582826721eda971535df2057e78fe to your computer and use it in GitHub Desktop.
Display the source code of a file with PHP highlighting.
<?php
/* examples of usage:
// in php block
$relativePathToFile = "folder/exampleFile.php";
ShowSourceCode.php?source_file=$relativePathToFile
// as html link
<a href="ShowSourceCode.php?source_file=exampleFile.php" target="blank">View the Source Code</a>
*/
if (isset($_GET['source_file'])) { // check if file name is given
if (file_exists($_GET['source_file'])) { // check if file exists
$SourceFile = file_get_contents(stripslashes($_GET['source_file']));
highlight_string($SourceFile);
} else {
echo "<p>Invalid source file name or path.</p>\n";
}
} else {
echo "<p>No source file name entered.</p>\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment