Last active
June 12, 2016 05:30
-
-
Save olzaragoza/ff3582826721eda971535df2057e78fe to your computer and use it in GitHub Desktop.
Display the source code of a file with PHP highlighting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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