How can I display code on a page without execution?

liunx

Guest
If I want to show code on a page, how do I do it without it actually executing in my real code?<!--content-->You have two options: One is using the depreciated (<!-- m --><a class="postlink" href="http://www.w3.org/TR/html4/appendix/changes.html#h-A.3.1.3">http://www.w3.org/TR/html4/appendix/cha ... #h-A.3.1.3</a><!-- m -->) <xmp>, the other is changing your < to &lt; The latter method is much better...<br />
<br />
<xmp><br />
<b>This will show up as code!</b><br />
</xmp><br />
<br />
<b>This will also show up as code, and will validate!</b><!--content-->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.<br />
<br />
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.<br />
<br />
Thanks for your help. You're great!<br />
<br />
Originally posted by pyro <br />
You have two options: One is using the depreciated (<!-- m --><a class="postlink" href="http://www.w3.org/TR/html4/appendix/changes.html#h-A.3.1.3">http://www.w3.org/TR/html4/appendix/cha ... #h-A.3.1.3</a><!-- m -->) <xmp>, the other is changing your < to &lt; The latter method is much better...<br />
<br />
<xmp><br />
<b>This will show up as code!</b><br />
</xmp><br />
<br />
<b>This will also show up as code, and will validate!</b><!--content-->lol..<br />
<br />
Let's go through it step by step. :)<br />
<br />
First of all, I don't understand what you are asking with this:<br />
<br />
I did a search/replace for the "<" and ">" characters and replaced with "<" and ">" respectively. Is that wrong?Could you come again on that one?<br />
<br />
No, the latter method (<) won't execute. It will look the same on the HTML page, as < is the HTML entity for a <<br />
<br />
Validate. If you run <xmp> through the W3C's validator (<!-- m --><a class="postlink" href="http://validator.w3.org">http://validator.w3.org</a><!-- m -->), it will not validate. Using < will, however.<br />
<br />
If you want your code to keep it's layout, you will have to add <br> after each line.<br />
<br />
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...<!--content-->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.<br />
<br />
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.<!--content-->Yes, that sounds correct... (though &#60; should work instead of &lt;)<!--content-->Let's make that last bit readable...<br />
(though &,#,6,0;[no commas] should work instead of <)<!--content-->Not sure what you are saying, but to display an & on these forums, you need to use &amp; (ie. &amp;lt; will display &lt; )<!--content-->I was...makin the smiley gone!...yea u accidentally left the "Disable Smilies for this Post" unchecked! I forgot how to display the "&"<!--content-->
 
Back
Top