[thelist] the ampersand & and similar entity type characters

Bob Meetin bobm at dottedi.biz
Sun Nov 8 11:41:28 CST 2009

John List wrote:
> Bob Meetin wrote:
>> Just curious here.  Can someone explain when/why it's compulsory to 
>> use the entity code rather than the character itself in a document.  
>> Commonly in validating pages, even the cryptic php strings they won't 
>> validate unless I convert & to &, etc.
>> With simple page titles like "Jack & Jill" they become "Jack & 
>> Jill".
>> Or perhaps:
>> index.php?option=page&id=3 becomes index.php?option=page&id=3
>> It's just  rather fatiguing...
>> -Bob
> Since the ampersand is the escape character for entity codes in an 
> HTML document, it needs to be escaped itself to avoid possible 
> ambiguity. Compare this to escaping the backslash when you really want 
> to use a backslash in a Javascript or PHP string.
> It's not compulsory, just "correct". Most browsers are forgiving and 
> will fall back to displaying the ampersand if they can't decipher the 
> entity code.
> What validation are you talking about? W3?
> What do you mean by "cryptic php strings"? (A good PHP code validator 
> would not require entity codes in a string since it's not part of an 
> HTML document.)
> John
Cryptic is not cryptic to me as I do this all day long, but commonly 
you'll see a very very long string with 3-4-5 options which appears 
cryptic to the regular user.  Sometimes you have to link this page in 
other pages, menus, etc.  The link works but then you pass it through 
the w3c validator and it complains, so I/you switch to the entitity code 
alternate and all is well in Bugsvillle.

In Joomla and perhaps the other CMS on an article page there is a page 
title, a simple input field.  The validator does not appreciate the use 
of "&" here.

Bob Meetin

More information about the thelist mailing list