[thelist] the ampersand & and similar entity type characters

John List johnlist at gulfbridge.net
Sun Nov 8 11:09:22 CST 2009


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



More information about the thelist mailing list