473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Code to display my code

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
5 2127
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
8
by: Kayda | last post by:
Hello: I had some code that allowed me to expand a paragraph by clicking on a hyperlink and collapse it by clicking on the paragraph. I unfortunately the Javascript function. I still have the...
6
by: christian9997 | last post by:
Hi I would be very helpful if someone could help me with this code. It works fine in IE but when I display it in Netscape or Firefox and I move the mouse from one menu to the other the gap...
2
by: LordBlue | last post by:
Hi, please forgive me if i'm sending this post in the wrong place, and please don't tell me to post it in another group, because if i found a better one i'd have already done it. I'm writing a...
0
by: George Hartas | last post by:
I am using Visual C# .NET 2003 to make a ComboBox accept both mouse and keyboard selection. For mouse selection code, I double-clicked ComboBox to get the default "comboBox1_SelectedIndexChanged"...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
12
by: StephQ | last post by:
I face the following problem. I wrote a poor's man plotting function: computePlot. This function append some x-values belonging to step and the correseponding f( x ) (for a given const member...
3
by: Danigan | last post by:
I could about swear this was working perfectly while I was adding some other functionality somewhere else. I now removed that functionality and it doesn't work. If someone could find what I broke,...
2
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
3
by: Hazza | last post by:
Hi, I am using PHP and mysql to create a website. I am fairly new to PHP, and thus am grateful to anyone who helps! Firstly I am running a homepage, that displays additional content if a user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.