[ Previous: C. Adding Your Own Tags | Next: E. Adding Enhanced Tags ]

D. Adding Your Own Smileys

Tags are good, but what about smileys, emoticons, the thing where the user types :-) and sees a little smiley-face icon appear in the output? NBBC includes full support for smileys, and includes a default selection of 30 fairly common ones. (You can find a full list of the standard smileys in the appendix.) But if those 30 aren't enough for you, installing your own is easy.

First, the smiley you want to add must be a PNG, GIF, or JPEG image file; browsers can't handle other file formats. Upload your image to the server, and then copy it into the smileys/ directory.

Then you'll have to choose a name for your smiley: You'll have to choose what people need to type to see it. Simple smileys like :-) are easy, but what if yours is a picture of, say, a dog driving a car? For complex smileys like this that can't be readily described by a simple symbol, most users generally prefer to use a short keyword surrounded by colons, like :dogcar:. Let's add the :dogcar: smiley so that NBBC will convert it into "dogcar.png":

$bbcode->AddSmiley(":dogcar:", "dogcar.png");

That's all it takes; the :dogcar: smiley is now available!

Tech Tip

For what it's worth, your smiley codes may include every character on your keyboard except for space, [, and ], which are all used by other things. Generally, you should never use smileys shorter than two characters long, and even that's probably too short, with some exceptions. And NBBC is smart enough to know that if :D and D: are smileys, it should not convert PAID: or :DUDE: just because they look like they have smileys in them: Any smiley that butts up against an alphanumeric character (or underscore) will not be converted to an image.

While you can register any sequence of characters as a smiley, it's usually a bad idea to register something that might be a commonly-typed word. For example, registering 83 is probably a bad idea, simply because the number "83" is likely to eventually appear in text somewhere. The last thing you ever want to see on your site is something like this:

83 people died in that plane crash.

This is why most unusual smileys on most sites are done with keywords surrounded by colons: If this smiley had been registered as :goofygrin: instead of as 83, this tragedy might have been averted.

So it's up to you what smileys you register, but be careful: Your smileys may have unintendend consequences if you don't think carefully about how they might be used.

[ Previous: C. Adding Your Own Tags | Next: E. Adding Enhanced Tags ]

Copyright © 2010, the Phantom Inker. All rights reserved.