Description
string
htmlentities ( string string [, int quote_style [, string charset]])
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.
Like htmlspecialchars(), the optional second
quote_style parameter lets you define what will
be done with 'single' and "double" quotes. It takes on one of three
constants with the default being ENT_COMPAT:
±í¸ñ 1. Available quote_style constants
| Constant Name | Description |
|---|
| ENT_COMPAT | Will convert double-quotes and leave single-quotes alone. |
| ENT_QUOTES | Will convert both double and single quotes. |
| ENT_NOQUOTES | Will leave both double and single quotes unconverted. |
Support for the optional quote parameter was
added in PHP 4.0.3.
Like htmlspecialchars(), it takes an optional
third argument charset which defines character
set used in conversion. Support for this argument was added in PHP 4.1.0.
Presently, the ISO-8859-1 character set is used as the default.
PHP 4.3.0 ¼°ÆäºóÐø°æ±¾Ö§³ÖÈçÏÂ×Ö·û¼¯¡£
±í¸ñ 2. ÒÑÖ§³Ö×Ö·û¼¯
| ×Ö·û¼¯ | ±ðÃû | ÃèÊö |
|---|
| ISO-8859-1 | ISO8859-1 |
Î÷Å·£¬Latin-1
|
| ISO-8859-15 | ISO8859-15 |
Î÷Å·£¬Latin-9¡£Ôö¼ÓÁË Latin-1£¨ISO-8859-1£©ÖÐȱÉÙµÄÅ·Ôª·ûºÅ¡¢·¨¹ú¼°·ÒÀ¼×Öĸ¡£
|
| UTF-8 | |
ASCII ¼æÈݶà×Ö½Ú 8-bit Unicode¡£
|
| cp866 | ibm866, 866 |
DOS-ÌØÓÐµÄ Cyrillic ×Öĸ×Ö·û¼¯¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
|
| cp1251 | Windows-1251, win-1251, 1251 |
Windows-ÌØÓÐµÄ Cyrillic ×Öĸ×Ö·û¼¯¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
|
| cp1252 | Windows-1252, 1252 |
Windows ¶ÔÓÚÎ÷Å·ÌØÓеÄ×Ö·û¼¯¡£
|
| KOI8-R | koi8-ru, koi8r |
¶íÎÄ¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
|
| BIG5 | 950 |
·±ÌåÖÐÎÄ£¬Ö÷ÒªÓÃÓÚÖйų́Íå¡£
|
| GB2312 | 936 |
¼òÌåÖÐÎÄ£¬¹ú¼Ê±ê×¼×Ö·û¼¯¡£
|
| BIG5-HKSCS | |
·±ÌåÖÐÎÄ£¬Big5 µÄÑÓÉ죬Ö÷ÒªÓÃÓÚÏã¸Û¡£
|
| Shift_JIS | SJIS, 932 |
ÈÕÎÄ¡£
|
| EUC-JP | EUCJP |
ÈÕÎÄ¡£
|
×¢:
ISO-8859-1 ½«´úÌæÈÎºÎÆäËüÎÞ·¨Ê¶±ðµÄ×Ö·û¼¯¡£
If you're wanting to decode instead (the reverse) you can use
html_entity_decode().
Àý×Ó 1. A htmlentities() example |
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
|
|
See also html_entity_decode(),
get_html_translation_table(),
htmlspecialchars(), nl2br(),
and urlencode().