By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

Code to display my code

P: n/a
Hi all,

I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think

Is there a way to do this?

TIA,

Miki
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Michelle wrote:
I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think

Is there a way to do this?


http://www.php.net/highlight_file

Example:

<?php
echo '<p>Hello World!</p>';
highlight_file($_SERVER['PHP_SELF']);
?>

The HTML output is (reformatted):

<p>Hello World!</p><code>
<font color="#000000">
<font color="#0000CC">&lt;?php<br /></font>
<font color="#006600">echo </font>
<font color="#CC0000">'&lt;p&gt;Hello World!&lt;/p&gt;'</font>
<font color="#006600">];<br/></font>
<font color="#0000CC">highlight_file</font>
<font color="#006600">(</font>
<font color="#0000CC">$_SERVER</font>
<font color="#006600">[</font>
<font color="#CC0000">'PHP_SELF'</font>
<font color="#006600">]</font>
<font color="#006600">);<br /></font>
<font color="#0000CC">?&gt;<br /></font>
</font>
</code>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

P: n/a
"Michelle" <miki@spam_me.net> wrote in message
news:J_RUb.240902$na.397133@attbi_s04...
Hi all,

I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think

Is there a way to do this?

TIA,

Miki


<HTML>
<BODY>
<?php
$whatFile = "source_php_file_";
highlight_file($whatFile)
?>
</BODY>
</HTML>

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #3

P: n/a
Michelle <miki@spam_me.net> wrote:
Hi all,

I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think

Is there a way to do this?


sounds like you want to use fopen, fread and fclose functions to read your
script into a variable and then display it.
your current script's filename is in the variable
$_SERVER["SCRIPT_FILENAME"]

so you'll end up with something like:

$filename = $_SERVER["SCRIPT_FILENAME"];
$filehandle = @fopen($filename, "r");
$contents = fread($filehandle, filesize($filename));
@fclose($handle);

next, display $contents in any way you like. you can also use file()
function to read the file into an array, etc.
note that the @ prevents error messages from displaying and revealing
your script's location when an error occurs, which is more secure.

steven.
Jul 17 '05 #4

P: n/a
I noticed that Message-ID: <J_RUb.240902$na.397133@attbi_s04> from
Michelle contained the following:
I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think


You could save the file with a .phps extension which makes the code
visible and nicely coloured.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5

P: n/a
Michelle <miki@spam_me.net> wrote or quoted:
I am taking a class in PHP and thought that it would be nice to display
the PHP code that generated my pages when the user clicked a link (or
submit button). I have seen page that will display the underlying HTML
on the page and it would be a nice touch...I think

Is there a way to do this?


There is PHP code to display HTML and PHP code (or a mixture of the two) -
with appropriate syntax highlighting for both languages - at:

http://mandala.co.uk/syntax_highlighting/
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.