PHP » PYTHON |
login |
register |
about
|
PYTHON htmlspecialchars_decode
is this article helpful?
|
Python replacement for PHP's htmlspecialchars_decode
[
edit
| history
]
import re try: from htmlentitydefs import entitydefs except ImportError: # Python 3 from html.entities import entitydefs def htmlspecialchars_decode_func(m, defs=entitydefs): try: return defs[m.group(1)] except KeyError: return m.group(0) # use as is def htmlspecialchars_decode(string): pattern = re.compile("&(\w+?);") return pattern.sub(htmlspecialchars_decode_func, string) htmlspecialchars_decode(PHP 5 >= 5.1.0) htmlspecialchars_decode — Convert special HTML entities back to characters Description
string htmlspecialchars_decode
( string $string
[, int $quote_style= ENT_COMPAT
] )
This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters. The converted entities are: &, " (when ENT_NOQUOTES is not set), ' (when ENT_QUOTES is set), < and >. Parameters
Return ValuesReturns the decoded string. Examples
Example #1 A htmlspecialchars_decode() example
<?php The above example will output: <p>this -> "</p> <p>this -> "</p>
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|