I am new to Python but have been working with PHP for a while. I am looking for a method to convert all characters (except [0-9A-Za-z ]
) to "HTML Decimal Entities". I have been searching around and haven't found a suitable method yet. I am looking for a carbon copy of this PHP method in Python.
The closest methods I have found are these in Python, but they don't exclude [0-9A-Za-z ]
: Python3 Convert all characters to HTML Entities and How can I escape *all* characters into their corresponding html entity names and numbers in Python?
Just like the PHP method, I want a function that can convert every character (current and future) excluding [0-9A-Za-z ]
to "HTML Decimal Entities" and where the UTF-8 character encoding is assumed.
E.g. "abcABC123 &%¤#"
would become "abcABC123 &%¤#"