Reputation: 31212
Is there a way to display the source code of somepage.php
when you go to somepagesrc.php
? IOW, is there a PHP function that will in somepagesrc.php
output the text contents of the file (or source code) somepage.php
?
I understand I could copy the contents of somepage.php
into somepage.html
but that doesn't cut it for me because I want it to be dynamic so that I don't have to copy the code over every time I make a change.
Upvotes: 1
Views: 8348
Reputation: 37331
Maybe use file_get_contents
along with header('Content-type: text/plain')
- but obligatory security warning - be sure to filter the names of files so people can't include more than you intent.
E.g.:
<?php
header('Content-type: text/plain');
print file_get_contents("somepage.php");
?>
Upvotes: 3
Reputation: 28901
Take a look at highlight_file()
. It not only grabs the php source to display (like file_get_contents()
) but nicely formats/colorizes the code for output.
http://php.net/manual/en/function.highlight-file.php
Upvotes: 0
Reputation: 530
Try easily to read its contents as any file using the file manipulation functions :) I don't know if that may be the solution you are searching about :$
Upvotes: 0
Reputation: 3401
or you could use Reflection
through which you could easily get functions, variables, and even comments.
http://www.php.net/manual/en/intro.reflection.php
Upvotes: 0