What’s the right way to decode a string that has special HTML entities in it? [duplicate]

This is my favourite way of decoding HTML characters. The advantage of using this code is that tags are also preserved. function decodeHtml(html) { var txt = document.createElement(“textarea”); txt.innerHTML = html; return txt.value; } Example: http://jsfiddle.net/k65s3/ Input: Entity:&nbsp;Bad attempt at XSS:<script>alert(‘new\nline?’)</script><br> Output: Entity: Bad attempt at XSS:<script>alert(‘new\nline?’)</script><br>

How do I decode HTML entities in Swift?

This answer was last revised for Swift 5.2 and iOS 13.4 SDK. There’s no straightforward way to do that, but you can use NSAttributedString magic to make this process as painless as possible (be warned that this method will strip all HTML tags as well). Remember to initialize NSAttributedString from main thread only. It uses … Read more

Decode HTML entities in Python string?

Python 3.4+ Use html.unescape(): import html print(html.unescape(‘&pound;682m’)) FYI html.parser.HTMLParser.unescape is deprecated, and was supposed to be removed in 3.5, although it was left in by mistake. It will be removed from the language soon. Python 2.6-3.3 You can use HTMLParser.unescape() from the standard library: For Python 2.6-2.7 it’s in HTMLParser For Python 3 it’s in … Read more