Click to See Complete Forum and Search --> : How can I display code on a page without execution?


Duke Will
07-25-2003, 10:37 AM
If I want to show code on a page, how do I do it without it actually executing in my real code?

pyro
07-25-2003, 10:41 AM
You have two options: One is using the depreciated (http://www.w3.org/TR/html4/appendix/changes.html#h-A.3.1.3) <xmp>, the other is changing your < to &amp;lt; The latter method is much better...

<xmp>
<b>This will show up as code!</b>
</xmp>

&lt;b>This will also show up as code, and will validate!&lt;/b>

Duke Will
07-25-2003, 11:11 AM
Before I saw your post, I did a search/replace for the "<" and ">" characters and replaced with "<" and ">" respectively. Is that wrong? It worked okay but did not honor the line breaks, so the code got all squished up. I was hoping to be able to show the code "as laid out" but so that it displays only and does not execute.

I don't understand what you said below. You said the latter that you gave is better but then you said it would "execute," so that means it's NOT better, correct? ??? Uh... wait, not sure what you mean by "validate." Maybe that's why i'm confused.

Thanks for your help. You're great!

Originally posted by pyro
You have two options: One is using the depreciated (http://www.w3.org/TR/html4/appendix/changes.html#h-A.3.1.3) <xmp>, the other is changing your < to &amp;lt; The latter method is much better...

<xmp>
<b>This will show up as code!</b>
</xmp>

&lt;b>This will also show up as code, and will validate!&lt;/b>

pyro
07-25-2003, 11:31 AM
lol..

Let's go through it step by step. :)

First of all, I don't understand what you are asking with this:

I did a search/replace for the "<" and ">" characters and replaced with "<" and ">" respectively. Is that wrong?Could you come again on that one?

No, the latter method (&lt;) won't execute. It will look the same on the HTML page, as &lt; is the HTML entity for a <

Validate. If you run <xmp> through the W3C's validator (http://validator.w3.org), it will not validate. Using &lt; will, however.

If you want your code to keep it's layout, you will have to add <br> after each line.

If you show me the code you want displayed on your page, I can show you how to write it so it displays as code...

Duke Will
07-25-2003, 11:55 AM
Okay, I think I understand you. What you said you didn't understand about my search and replace... I think it did not display as I intended. I did a search and replace (for the section of code I wanted to display) and replace the "<" character with... uh... how do I show this... &, #, 6, 0, ; (not the commas.

So, if I understand you, I can replace the "<" with &,l,t,; (no commas)... AND... i will have to actually KEEP the BREAK tags in there to break the lines as i wish.

pyro
07-25-2003, 11:58 AM
Yes, that sounds correct... (though &amp;#60; should work instead of &amp;lt;)

neenach2002
07-25-2003, 12:05 PM
Let's make that last bit readable...
(though &,#,6,0;[no commas] should work instead of &lt;)

pyro
07-25-2003, 12:08 PM
Not sure what you are saying, but to display an & on these forums, you need to use &amp;amp; (ie. &amp;amp;lt; will display &amp;lt; )

neenach2002
07-25-2003, 12:18 PM
I was...makin the smiley gone!...yea u accidentally left the "Disable Smilies for this Post" unchecked! I forgot how to display the "&amp;"