def htmldec(text):
    """Decode HTML entities in the given text."""
    chunks = text.split('&#')
    for i in range(1, len(chunks)):
        number, rest = chunks[i].split(';', 1)
        chunks[i] = chr(int(number)) + rest
    text = ''.join(chunks)
    text = text.replace('\xa0', ' ')
    text = text.replace('&nbsp;', ' ')
    text = text.replace('&lt;', '<')
    text = text.replace('&gt;', '>')
    text = text.replace('&quot;', '"')
    text = text.replace('&amp;', '&')
    return text