www.webdeveloper.com
Results 1 to 9 of 9

Thread: How can I display code on a page without execution?

  1. #1
    Join Date
    Jul 2003
    Location
    Louisiana
    Posts
    326

    How can I display code on a page without execution?

    If I want to show code on a page, how do I do it without it actually executing in my real code?

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You have two options: One is using the depreciated <xmp>, the other is changing your < to &amp;lt; The latter method is much better...

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

  3. #3
    Join Date
    Jul 2003
    Location
    Louisiana
    Posts
    326

    I kinda did it but

    Before I saw your post, I did a search/replace for the "<" and ">" characters and replaced with "&#60;" and "&#62;" 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 <xmp>, the other is changing your < to &amp;lt; The latter method is much better...

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

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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, 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...

  5. #5
    Join Date
    Jul 2003
    Location
    Louisiana
    Posts
    326

    okay got it

    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.

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, that sounds correct... (though &amp;#60; should work instead of &amp;lt;)

  7. #7
    Join Date
    Apr 2003
    Location
    Canyon Country, CA
    Posts
    734
    Let's make that last bit readable...
    (though &,#,6,0;[no commas] should work instead of &lt;)

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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; )

  9. #9
    Join Date
    Apr 2003
    Location
    Canyon Country, CA
    Posts
    734
    I was...makin the smiley gone!...yea u accidentally left the "Disable Smilies for this Post" unchecked! I forgot how to display the "&amp;"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles