Skip to content

Instantly share code, notes, and snippets.

@schocco
Created February 7, 2012 22:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schocco/1762611 to your computer and use it in GitHub Desktop.
Save schocco/1762611 to your computer and use it in GitHub Desktop.
encode any string to html
# can be used to hide email addresses in the html source of Web sites from spiders
def html_encode(email):
'''
Takes a unicode string as only parameter and returns
a sequence of html encoded chars.
>>> html_encode(u"test@website.org")
'test@website.or&#103'
'''
list = []
for char in email:
list.append("&#%s" % ord(char))
return ";".join(list)
@rchrd2
Copy link

rchrd2 commented Jan 19, 2016

Seriously the only example I could find that escapes ALL characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment