1

This might seem like a stupid question but I have always wondered. What would be the advantage of using HTML code names versus HTML code numbers. Is there a right place or a wrong place for each version?

By HTML codes I am referring to this..

http://ascii.cl/htmlcodes.htm

I know for validation purposes codes should be used for example using & or & versus using &. However I don't know when it would be right to use & over & ... or does it simply make no difference?

khollenbeck
  • 16,028
  • 18
  • 66
  • 101
  • **as I know**, they have same behavior but using names is much easier :-) – undone May 02 '12 at 15:43
  • possible duplicate of [Character Entity References - numeric or not?](http://stackoverflow.com/questions/5420190/character-entity-references-numeric-or-not) – Jukka K. Korpela May 02 '12 at 19:13

4 Answers4

3

It makes no difference. The reason why, for example, & was created was to make it easier for coders to remember and make code easier to read.

It just comes down to, one is easier for us (humans) to read.

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
2

Some terminology: A code like "&" is properly called a character entity reference; a code like "&" is a numeric character reference.

Together, we can refer to them all as "HTML entities." For a given code point, there is sometimes a character entity reference, but there is always a numeric character reference, which can be formed from the Unicode encoding of the character. For instance, ℛ has the numeric character reference "ℛ".

Generally it's the ASCII characters that have character entity references, but not always.

Character entity references are usually easier to read, but in a particular context a set of numeric character references might possibly be. For instance, if you were writing a regular expression to match a certain block of Unicode characters.

When you say "for validation purposes codes should be used," I think you have in mind the rule that a bare ampersand is not valid HTML. That's specific to this character.

Update

An example where you have to use the numeric character entity: There is no character entity reference for the single quote character, "'". A piece of JavaScript to scrub quote characters out of a string has to use the numeric character entity.

Community
  • 1
  • 1
David Gorsline
  • 4,933
  • 12
  • 31
  • 36
0

Using names is always preferrable, as it is always more readable. Consider the following pieces of identical code:

$location = "Faith Life Church";
$city = "Sarasota";
/*...*/
foreach ($stmt as $row) {
    foreach ($row as $variable => $value) {
        $variable = strtolower($variable);
        $$variable = $value;
    }

}

And

$v073124 = "Faith Life Church";
$v915431 = "Sarasota";
/*...*/
foreach ($v3245 as $v9825) {
    foreach ($v9825 as $v85423 => $v8245631) {
        $v85423 = strtolower($v85423);
        $$v85423 = $v8245631;
    }

}

Which would you consider more readable?

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
-1

It's your choice. Code may be easier for someone to remember instead of letters.

BUT I think HTML 5 require you using letters as a standard for what you can. Really not sure about this.

David Bélanger
  • 7,400
  • 4
  • 37
  • 55