SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    How to output & a m p ; (ampersand) as a ampersand?

    As you know if you put
    Code:
    &
    ampersand it outputs &. I have tried wrapping it in code tags and pre. Neither worked. I have searched but only thing I could find is everyone asking the opposite.

  2. #2
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    You cannot in normal flow as ampersand character ("&") declares the beginning of an entity reference so you'd use NCR, i.e.: & and that would render the following: &

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Awesome thank you much!

  4. #4
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,882
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    As you know if you put
    Code:
    &
    ampersand it outputs &. I have tried wrapping it in code tags and pre. Neither worked. I have searched but only thing I could find is everyone asking the opposite.
    The easiest way I find is to put an empty tag in the middle, along the lines of &[b][/b]amp;. That breaks up the entity and then the forum software doesn't recognise it and shows it intact.

    Off Topic:

    Moved to 'forum support' section.

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    What I do is similar to Stevie. I wrap part of the entity with the color black.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Thanks but no need to move it. As this was not for BBcode. It was for some code output on my site. AKA html code.

  7. #7
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,882
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    Thanks but no need to move it. As this was not for BBcode. It was for some code output on my site. AKA html code.
    Gotcha. Even easier than Robert 's way, because it saves you remembering the hex code, is &, which does exactly the same but with named entities.

  8. #8
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    cool cool good to know. Thanks

  9. #9
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    NCRs (numeric character references) and 'character entity references' are types of character escape used in markup. Getting back to the question NCR is the preferable choice over the entities, entities are limited to a subset of Unicode characters, NCR can specify any character and theoretically Hexadecimal has less ambiguity. NCR for the win.

    NCR as explained are more functional. HTML 4.01 has 252 Character entity references: http://www.w3.org/TR/html401/sgml/entities.html For X(HT)ML an application of XML, we have the XML specification that defines five "predefined entities" only: http://www.w3.org/TR/REC-xml/#sec-predefined-ent hence NCR should only be used if authoring XHTML and not using one of those 5 and HTML 4.01 only has 4 of those.

    Numeric character references, both decimal and hexadecimal, can be safely used in (X)HTML and XML, but you need to be careful that you're referencing the character's code point from the Unicode character repertoire, not Windows-1252.


Bookmarks

Posting Permissions

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