HTML Entities Primer Tutorial

HTML Entities Primer Tutorial

HTML Entities Primer Tutorial

As a programmer, when you deal with database issues and CSV you often come up with issues where you construct HTML or read HTML as part of the final solution, and you have to deal with the ambiguity of ‘ and , characters, respectively, having dual purposes. The ‘ delimits characters in SQL for the databases MySql, MS-SQL, Oracle, Access and others. The , character is the default delimiter for CSV data and lists of things that you “split” or “explode” into an array. But this can be problematic, in that ‘ and , can also naturally exist in a person’s name, or their address, for instance.

This is the situation where HTML entities can be very useful, as they can replace your delimiters (‘ and , are just two examples, but the method can apply to others as well) with what is known as HTML entities, to avoid any data confusion for the use of this data by Javascript and/or PHP or any other client/server-side language combinations you are using.

Let’s take a look at Wikipedia’s write up regarding HTML entities.

In SGML, HTML and XML documents, the logical constructs known as character data and attribute values consist of sequences of characters, in which each character can manifest directly (representing itself), or can be represented by a series of characters called a character reference, of which there are two types: a numeric character reference and a character entity reference. This article lists the character entity references that are valid in HTML and XML documents.

Although in popular usage character references are often called “entity references” or even “entities”, this usage is wrong.[citation needed] A character reference is a reference to a character, not to an entity. Entity reference refers to the content of a named entity. An entity declaration is created by using the syntax in a document type definition (DTD) or XML schema. Then, the name defined in the entity declaration is subsequently used in the XML. When used in the XML, it is called an entity reference.

Now let’s see a good link listing a lot of the HTML entities of use here.

As the programmer confronted with such issues Javascript’s replace and PHP’s str_replace come in really handy.

Example code snippets are shown below:

  • str_replace("'", "’", $myPHPvar); // replace all ‘ with its HTML entity in PHP
  • str_replace(",", ",", $myPHPvar); // replace all HTML entity occurrences back to , in PHP
  • myJavascriptVar.replace(/,/g, ","); // replace all , with its HTML entity in Javascript
  • myJavascriptVar.replace(/’/g, "'"); // replace all HTML entity occurrences back to the original ‘ character in Javascript

Of course, this is like a “first principles” talk above, but, as you can imagine with such a fundamental subject, the languages have catered well for the thousands of other ways “to skin a cat” … meeeeeeeeeeeeoooooooowwwwww! … sorry, kitty … and we’ll leave you with some good links here … so, chou for now … tee, hee …

|| chortle, chortle.

Here is a Yahoo Answers question regarding this topic area … What is &raquo used when coding?

If this was interesting you may be interested in this too.

This entry was posted in Database, eLearning, Tutorials and tagged , , , , , , , , . Bookmark the permalink.

5 Responses to HTML Entities Primer Tutorial

  1. over here says:

    So happy to get identified this article.. Wonderful thought processes you have got here.. Loving the page.. thanks alot :) Enjoy the posting you presented..

  2. Fantastic says:

    Is not it fantastic whenever you come across an excellent publish? So pleased to have found this article.. I value you revealing your perspective.. So content to have found this article..

  3. KW 1..2015 says:

    But a smiling visitant here to share the love (:, btw great pattern .

  4. Sweet says:

    I appreciate you telling your point of view.. Is not it good once you find a good submit? Excellent thoughts you possess here.. Value the admission you available..

  5. NICOLE says:

    I used to be able to find good advice from your content.|

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>