Thursday, 6 December 2012

Creating Entities

Entities, such as an ampersand (&) or the copyright logo, are special characters that would not appear on a standard english QWERTY keyboard, in a program like word, for example, you would have to sort through the Insert -> Add Symbol Pane for quite a while to find the right one. However, HTML supports a create entity function. Besides the use of special characters, other characters, such as the ampersand, are on the keyboard put may be used to denote other tasks, thus must be created as an entity in order to prevent HTML confusing itself and mistaking it for a function, not a character.

To create an entity first create, or use one fo your existing files if you have one, a set of body tags like this;

...
<body>
<p> This is where we will create our entity </p>

</body>
</html>

Now in the marked location, for this 'tutorial' I will be using a simply copyright statement and a trademark on a random non-existant company that I will make up but you can type any content you want.

First we need to basic statement. Something like this should suffice;

Copyright (entity) of xrobot(entity) ltd. All Rights Reserved

Very simple, now for the real meat, the coding for entities. This comes in the addition of our old friend, the ampersand (&) generally located as SHIFT+7 on a standard QWERTY keyboard, this indicates that the following 'attribute' is a special character and should be ignored as anything other, such as a function. For example, the entity for the copyright 'C' and the trademark 'TM' is

&copy

&trade

If we now type this line of code instead into our html body tag, then we should end up with an output similar to the one in the coming image;

<p> Copyright &copy; of xrobot &trade; ltd. All Rights Reserved.

It is important to include the semi-colon after the end of the entity, ot the browser will try to find an entity relating to all the content after the ampersand and will result in no outputed entity.
You should get something similar to this;


There are more entity commands to be found if you search for them but next to look at will be a little break from all the functions and tags, and looking at something that looks serious, but could be good for a december prank to pull on your friends!

No comments:

Post a Comment