PHP » PYTHON |
login |
register |
about
|
PYTHON htmlentities
is this article helpful?
|
Python replacement for PHP's htmlentities
[
edit
| history
]
import cgi cgi.escape(unicode_string,quote=False).encode('ascii', 'xmlcharrefreplace') print cgi.escape('<b>bold</b>รค').encode('ascii', 'xmlcharrefreplace') result: <b>bold</b>ä the quote parameter behaves like: ENT_COMPAT when True ENT_NOQUOTES when False if html.escape (rom the html package) is used instead of cgi.escape then quotes=True will behave like ENT_QUOTES. NOTE: the html module is only available in python 3.x use cgi otherwise htmlentities(PHP 4, PHP 5) htmlentities — Convert all applicable characters to HTML entities Description
string htmlentities
( string $string
[, int $quote_style= ENT_COMPAT
[, string $charset
[, bool $double_encode= true
]]] )
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities. If you're wanting to decode instead (the reverse) you can use html_entity_decode(). Parameters
Return ValuesReturns the encoded string. Changelog
Examples
Example #1 A htmlentities() example
<?php
See Also
|
more
Recently updated
more
Most requested
|