1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: HTML character codes display the characters

Discussion in 'Site Help & Feedback' started by Ent, Jul 19, 2012.

Advertisement
  1. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    I noticed in this thread that while & " < and > display as typed on the forums, their numeric equivalents are automatically replaced with the character they represent. For example if I type (without the underscores) &_#_38_; I'd get & or if I typed &_#_8730_; I'd get √

    This could be frustrating, especially in the webDev forum, because such codes should be embedded literally in HTML. It's fairly easy to work around of course; one can tell people to remove the underscores. However if it's easy to add &# to the list including & and their ilk, it would be convenient to have them displayed literally. This is especially true in
    HTML:
    <h1>HTML CODE</h1>
    boxes.
     
  2. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Hmm... I agree. It'd be better not to have that displayed. Of course, we're not actually doing the replacement on our end. We send the &... code to your browser and it displays the special character. It would be nice if there was some simple HTML we could use (like <pre>) to tell the browser to simply display it as we send it rather than replacing it with the special characters, but I don't know of any way to do that. (Let me know if you discover otherwise!)

    I think I may need to write some code that will look at the text in the CODE boxes and replace instances of & with &_amp; (without the underscore), which I think would solve the problem...
     
  3. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    &amp; and the other named ones works fine; I guess BBCode already has the sense to escape those.
    It's just the numerical codes that break. You can't, for example, tell someone how to embed a squareroot sign in their web page because the browser just displays the squareroot sign.

    Edit: Yes, the forum turns &amp; to &amp;amp; automatically.
     
  4. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    That makes sense -- you're technically not supposed to send just & to a browser -- it's always supposed to be &amp; in order to pass validation. So it's good that vBulletin is doing that automatically. I could just copy that function and do it for all instances of & but that would prevent people from being able to use special characters in normal posts... (not a big deal to me, but I'm sure some find it useful / fun?) I'll have to find a smarter way to do so only in Code boxes. I think that would solve the issue, right?
     
  5. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    I think so.
    I'd extend that to the &#91;HTML&#93; boxes too.
    And yes, I do see that being able to force certain characters to display literally has its advantages.
     
  6. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Code:
    This is a test &amp; I just typed the full &amp; to see what it will do...
    &#8730
    
     
  7. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    So that seems to work... unless you quote or the post, in which case the browser is changing it back to the symbol... hmm...

     
  8. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Another test...

    Code:
    This is a test &amp; I just typed the full &amp; to see what it will do...
    &#8730
    Also, a reminder to myself: Once I get this figured out, do the same for HTML
     
  9. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Code:
    This is a test &amp; I just typed the full &amp; to see what it will do...
    &#8730
     
  10. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Code:
    This is a test &amp; I just typed the full &amp; to see what it will do...
    &#8730
    HTML:
    This is a test &amp; I just typed the full &amp; to see what it will do...
    &#8730
     
  11. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    HTML:
    <H1>Without Semicolon at end &#9785</H1>
    
    HTML:
    <H1>With Semicolon at end &#9785;</H1>
    
    Code:
    <H1>Without Semicolon at end &#9785</H1>
    
    Code:
    <H1>With Semicolon at end &#9785;</H1>
    
    Punctuation can be very annoying sometimes.
    &#9785;
     
  12. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Code:
    <H1>Without Semicolon at end &#9785</H1> 
    <H1>With Semicolon at end &#9785;</H1>
     
  13. TechGuy

    TechGuy Mike Administrator

    Joined:
    Feb 12, 1999
    Messages:
    13,263
    Sorry, I hard my mode turned off when you posted that. With my mod turned on, it seems to work either way... unless you quote or edit. :(
     
  14. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    Code:
    <H1>With Semicolon at end &#9785;</H1>
    
     
  15. Ent

    Ent Josiah Trusted Advisor Thread Starter

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    It works!
    Very impressive.

    &#9786;
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...

Short URL to this thread: https://techguy.org/1061679