Insert Special Characters on Your Page


Have you ever seen the copyright notice at the bottom of a Web page and wondered where they found the symbol? After all, it’s not on the keyboard. How did they get it onto the page? Let’s say you’re doing a mathematical formula and you want to place a < or > sign on your page. If you just type in the characters, the Web browser will interpret them as HTML markup. Not only will the characters not appear, they very likely will cause your page to display incorrectly. The same holds true with marks like the ampersand (&) and quotation marks. If you have JavaScript or another scripting language on your page, browsers can misinterpret these characters, too. So how do you instruct a Web browser to display special characters rather than ignoring them or treating them as code? Perhaps you want to include a word from a foreign language and you need a special symbol or accent. What do you do? The way around this and similar problems is through the use of entities.

Understand Entities

Simply put, an entity is a character that either is not accessible through your keyboard or one that will be incorrectly interpreted by the browser. However, these characters are resident in your computer’s system, and you can access them through the use of special codes.

The source for entity codes is the ISO-Latin1 character set. ISO stands for the International Standards Organization. The rest of the term denotes that this character set is derived from the Latin (or Roman) alphabet. Of course, there are many other character sets, derived from different alphabets. But the one you are most likely to use is ISO Latin-1; this also is the default character set for the Web.

Note

Entities described by numbers are called numeric entities. Entities described by descriptive terms are called character entities. Many special characters are represented by both types. For example, the copyright symbol can be written either as a numeric entity, &#169;, or as a character entity, &copy;. Whichever you use, a Web browser will recognize it as the entity for the copyright symbol and display the symbol in its place.

An entity must be constructed properly for the browser to recognize it. It always begins with an ampersand (&) and closes with a semicolon (;). In between, you insert either a numeric code or a logical descriptive term. In addition, numeric entities must have the number symbol (#) preceding the entity number. Also, entities are case sensitive; always type them in exactly as you see them on a reference chart. Incidentally, some older browsers might not recognize particular character entities. It’s always a good idea to test your page in different browsers to be sure of its compatibility.

Tip

For an extensive chart of numeric and character entities, download Appendix C from the author’s Web site at www.jamespence.com.

Insert an Entity in a Web Page

A practical way to experiment with entities is by adding a copyright notice to your Web page. To use the entity for the copyright symbol, follow these steps:

  1. Open template.htm and save it as entity.htm.

  2. In the <body> section of the document, type Copyright 2015.

  3. After the word Copyright, type the ampersand character, &.

  4. Enter either the numeric or character code. For example, for the copyright symbol you would type copy or #169.

  5. Close out the code by typing a semicolon. Your text should look like this:

    Copyright &copy; 2015 or Copyright &#169; 2015

However, on a Web browser it will display this way: Copyright 2015. Try it out on a sample page. Remember to put the entities in the actual text of your Web page, not in the tags. It would be incorrect to write <h6 &copy;>Copyright 2015</h6>. If you do put the entity in the wrong place, the browser will just ignore it. Type in the following code for a demonstration of how entities work and for a sample of what shows up when they are entered correctly:

<html>      <head>           <title>Sample Entity Display</title>      </head>      <body>           Copyright &copy; 2015           My Trademark &#174; is a registered trademark.      </body> </html>

When you save and display this page, you’ll notice, as in the illustration that follows, that the code for your entity is replaced by the special character that it represents:

click to expand




How to Do Everything with HTML & XHTML
How to Do Everything with HTML & XHTML
ISBN: 0072231297
EAN: 2147483647
Year: 2003
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net