def encode_emoticons(string):
    """ Returns the string with emoticons encoded as entities, e.g., :-) => &happy;
    """
    string = " " + string + " "
    for (smileys, entity) in (
      ((":)", ":-)"), "&happy;"),
      ((":(", ":-("), "&sad;")):
        for smiley in smileys:
            string = string.replace(" %s " % smiley, " %s " % entity)
    return string[1:-1]