def _htmlescape(string):
    """
    Convert problematic characters in string to use HTML entities.
    Handles angle brackets, double quotes and ampersand.
    """
    for char, rep in [('&', 'amp'), ('<', 'lt'), ('>', 'gt'), ('"', 'quot')]:
        string = string.replace(char, '&%s;' % rep)
    return string