Skip to main content
Inspiring
July 21, 2006
Answered

Amperstands in text

I was doing some testing of some CF pages that I developed and ran across a problem I've not seen discussed. I am pulling information from a database and have found that occasionally there are amperstands in the data that I'm displaying (a company name like Johnson & Johnson, for example). The page displays ok in IE, but it doesn't validate when using the validator at w3.org.

My questions are these: should I care that these pages won't validate? Might there be browsers that wouldn't display this information correctly? If so, should I be doing a replace(myfield,"&", "&", "all") everytime I display a text field just in case the data contains an amperstand?
    This topic is closed to new replies. Start a new post to keep the conversation going.
    DeliKCorrect answer
    Inspiring
    July 21, 2006
    Actually it was HTML 4.01 Transitional.

    Now that I've just installed FireFox on this computer today, I don't seem to have a problem with it anymore. Not sure why, I didn't change the CF code. It wouldn't validate because of the & yesterday, but does validate with it today. The only thing that changed was that I installed FireFox on this computer. Guess I'll just let it be until I see a problem again.

    Thanks, anyway, for all your suggestions.

    5 replies

    Participating Frequently
    July 21, 2006
    What DOCTYPE do you have at the top of the page that's failing validation? My guess is it's an XHTML doctype.

    If you're pushing an XHTML doctype, then you really should replace any occurrences of & with &

    Another alternative is, if you don't know why you're pushing an XHTML doctype, to switch to an HTML 4.01 doctype (either strict or transitional).
    Translate
    DeliKAuthorCorrect answer
    Inspiring
    July 21, 2006
    Actually it was HTML 4.01 Transitional.

    Now that I've just installed FireFox on this computer today, I don't seem to have a problem with it anymore. Not sure why, I didn't change the CF code. It wouldn't validate because of the & yesterday, but does validate with it today. The only thing that changed was that I installed FireFox on this computer. Guess I'll just let it be until I see a problem again.

    Thanks, anyway, for all your suggestions.
    Translate
    Inspiring
    July 21, 2006
    You are probably ok for the foreseeable future, unless some other
    requirement comes along that you have to be compliant. I'm fairly
    confident browsers will always display an & as an &.

    But it could become an issue if you ever need to use the text in any
    kind of XML application.

    DeliK wrote:
    > I was doing some testing of some CF pages that I developed and ran across a
    > problem I've not seen discussed. I am pulling information from a database and
    > have found that occasionally there are amperstands in the data that I'm
    > displaying (a company name like Johnson & Johnson, for example). The page
    > displays ok in IE, but it doesn't validate when using the validator at w3.org.
    >
    >
    > My questions are these: should I care that these pages won't validate? Might
    > there be browsers that wouldn't display this information correctly? If so,
    > should I be doing a replace(myfield,"&", "&", "all") everytime I display a
    > text field just in case the data contains an amperstand?
    >
    Translate
    Inspiring
    July 21, 2006
    Browse your page with Firefox. Does it look ok?
    Translate