I've got a .php file with javascript, php, and html. I want to include a button/link to view the source of the entire file "pretty printed", but I can't seem to get anything to work. What is the best way to do this?
+2
A:
If you simply want to display the code of the file, you can call this function:
function echoFile($pathToFile){
$handle = fopen($pathToFile, "r");
$contents = fread($handle, filesize($pathToFile));
fclose($handle);
$contents = str_replace("<", "<", $contents);
$contents = str_replace(">", ">", $contents);
echo "<pre>$contents</pre>";
}
So, if you want to display myPhpFile.php, just do
echoFile("myPhpFile.php");
As far as making it prettified, follow the link that was commented.
Andy Groff
2010-09-26 06:33:34
+2
A:
Some combinations of Apache/PHP are configured so that files ending in .phps
aren't run as PHP, but instead, highlighted and prettified.
Example:
Delan Azabani
2010-09-26 06:36:14