PHP » PYTHON |
login |
register |
about
|
PYTHON html_entity_decode
is this article helpful?
|
Python replacement for PHP's html_entity_decode
[
edit
| history
]
import htmlentitydefs import re pattern = re.compile("&(\w+?);") def html_entity_decode_char(m, defs=htmlentitydefs.entitydefs): try: return defs[m.group(1)] except KeyError: return m.group(0) def html_entity_decode(string): return pattern.sub(html_entity_decode_char, string) print html_entity_decode("<spam&eggs>") # <spam&eggs> html_entity_decode(PHP 4 >= 4.3.0, PHP 5) html_entity_decode — Convert all HTML entities to their applicable characters Description
string html_entity_decode
( string $string
[, int $quote_style= ENT_COMPAT
[, string $charset
]] )
html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities to their applicable characters from string . Parameters
Return ValuesReturns the decoded string. Changelog
Examples
Example #1 Decoding HTML entities
<?php
Notes
See Also
|
more
Recently updated
more
Most requested
|