Display PHP source at bottom of page
Moderator: General Moderators
Display PHP source at bottom of page
I know this isn't something people would typically want for a real site. But I'm currently in the process or learning PHP. My friend is giving me "homework assignments" and then I'll show them to him at the due dates. I would really like it if the PHP code was at the bottom of my pages. Can anyone think of a way to do this?
-
mikecampbell
- Forum Commoner
- Posts: 38
- Joined: Tue Oct 12, 2010 7:26 pm
Re: Display PHP source at bottom of page
You can use $_SERVER['SCRIPT_FILENAME'] to get the current script, and then use one of the file system functions like file_get_contents() to read the file. Then just dump the contents to the screen, replacing line breaks with <br>s.
Re: Display PHP source at bottom of page
You're the man! Thank you, my previous problem was I was using
But your suggestion works perfect:
Code: Select all
$_SERVER['PHP_SELF']Code: Select all
<?php
$file = $_SERVER['SCRIPT_FILENAME'];
$fh = fopen($file, 'r') or die('Could not open file!');
$data = file($file) or die('Could not read file!');
foreach ($data as $line){
echo $line."<br />";
}
?>Re: Display PHP source at bottom of page
Code: Select all
//.... your php code here ....
highlight_file(__FILE__);