I am looking for a way, preferably in python, but PHP is also ok or even an online site, to convert a string like
"Wählen"
into a string like
"Wählen"
i.e. replacing each ISO 8859-1 character/symbol by its HTML entity.
echo htmlentities('Wählen', 0, 'utf-8');
^ PHP
PS: Learn the arguments based on where you need the encoded string to appear:
// does not encode quotes
echo htmlentities('"Wählen"', 0, 'utf-8');
// encodes quotes
echo htmlentities('"Wählen"', ENT_QUOTES, 'utf-8');
For Python3
>>> import html.entities
>>> reventities = {k:'&'+v+';' for v,k in html.entities.entitydefs.items()}
>>> "".join(reventities.get(i, i) for i in "Wählen")
'Wählen'
Another (probably faster) way
>>> toentity = {k: '&'+v+';' for k,v in html.entities.codepoint2name.items()}
>>> "Wählen".translate(toentity)
'Wählen'