htmlentities

(PHP 4, PHP 5, PHP 7)

htmlentities锟斤拷锟街凤拷转锟斤拷为 HTML 转锟斤拷锟街凤拷

说锟斤拷

htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] ) : string

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟芥都锟斤拷 htmlspecialchars() 一锟斤拷锟斤拷 锟斤拷锟斤拷 htmlentities() 锟斤拷转锟斤拷锟斤拷锟叫撅拷锟斤拷 HTML 实锟斤拷锟斤拷址锟斤拷锟�

锟斤拷锟揭拷锟斤拷耄拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷使锟斤拷 html_entity_decode()锟斤拷

锟斤拷锟斤拷

string

锟斤拷锟斤拷锟街凤拷锟斤拷

flags

锟斤拷锟斤拷一锟斤拷位锟斤拷锟斤拷锟角o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷未锟斤拷锟斤拷锟斤拷拧锟斤拷锟叫э拷锟斤拷锟斤拷锟斤拷小锟绞癸拷锟斤拷牡锟斤拷锟斤拷锟斤拷汀锟� 默锟斤拷锟斤拷 ENT_COMPAT | ENT_HTML401锟斤拷

锟斤拷效 flags 锟斤拷浅锟斤拷锟�
锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷
ENT_COMPAT 锟斤拷转锟斤拷双锟斤拷锟脚o拷锟斤拷转锟斤拷锟斤拷锟斤拷锟脚★拷
ENT_QUOTES 锟斤拷转锟斤拷双锟斤拷锟斤拷也转锟斤拷锟斤拷锟斤拷锟脚★拷
ENT_NOQUOTES 锟斤拷/双锟斤拷锟脚讹拷锟斤拷转锟斤拷
ENT_IGNORE 锟斤拷默锟斤拷锟斤拷锟斤拷效锟侥达拷锟诫单元锟斤拷锟叫o拷锟斤拷锟斤拷锟角凤拷锟截匡拷锟街凤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷使锟矫此憋拷牵锟� 锟斤拷为锟斤拷» 锟斤拷锟斤拷锟叫帮拷全影锟斤拷锟斤拷
ENT_SUBSTITUTE 锟芥换锟斤拷效锟侥达拷锟诫单元锟斤拷锟斤拷为 Unicode 锟斤拷锟斤拷锟斤拷锟絉eplacement Character锟斤拷锟斤拷 U+FFFD (UTF-8) 锟斤拷锟斤拷 � (锟斤拷锟斤拷)锟斤拷锟斤拷锟斤拷锟角凤拷锟截匡拷锟街凤拷锟斤拷锟斤拷
ENT_DISALLOWED 为锟侥碉拷锟斤拷锟斤拷效锟斤拷锟斤拷锟斤拷婊晃� Unicode 锟斤拷锟斤拷锟斤拷锟絉eplacement Character锟斤拷锟斤拷 U+FFFD (UTF-8)锟斤拷锟斤拷 �锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角帮拷锟斤拷锟斤拷锟斤拷锟斤拷原锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷戮秃锟斤拷锟斤拷茫锟揭拷锟街� XML 锟侥碉拷嵌锟斤拷锟斤拷锟斤拷锟斤拷锟绞憋拷锟绞斤拷戏锟斤拷锟�
ENT_HTML401 锟斤拷 HTML 4.01 锟斤拷锟斤拷锟斤拷搿�
ENT_XML1 锟斤拷 XML 1 锟斤拷锟斤拷锟斤拷搿�
ENT_XHTML 锟斤拷 XHTML 锟斤拷锟斤拷锟斤拷搿�
ENT_HTML5 锟斤拷 HTML 5 锟斤拷锟斤拷锟斤拷搿�

encoding

An optional argument defining the encoding used when converting characters.

If omitted, the default value of the encoding varies depending on the PHP version in use. In PHP 5.6 and later, the default_charset configuration option is used as the default value. PHP 5.4 and 5.5 will use UTF-8 as the default. Earlier versions of PHP use ISO-8859-1.

Although this argument is technically optional, you are highly encouraged to specify the correct value for your code if you are using PHP 5.5 or earlier, or if your default_charset configuration option may be set incorrectly for the given input.

支锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷

支锟街碉拷锟街凤拷锟斤拷锟叫憋拷
锟街凤拷锟斤拷 锟斤拷锟斤拷 锟斤拷锟斤拷
ISO-8859-1 ISO8859-1 锟斤拷欧锟斤拷Latin-1
ISO-8859-5 ISO8859-5 Little used cyrillic charset (Latin/Cyrillic).
ISO-8859-15 ISO8859-15 锟斤拷欧锟斤拷Latin-9锟斤拷锟斤拷锟斤拷欧元锟斤拷锟脚o拷锟斤拷锟斤拷头锟斤拷锟斤拷锟斤拷锟侥革拷锟� Latin-1(ISO-8859-1) 锟斤拷缺失锟斤拷
UTF-8   ASCII 锟斤拷锟捷的讹拷锟街斤拷 8 位 Unicode锟斤拷
cp866 ibm866, 866 DOS 锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷搿o拷锟斤拷址锟斤拷锟斤拷锟� 4.3.2 锟芥本锟叫得碉拷支锟街★拷
cp1251 Windows-1251, win-1251, 1251 Windows 锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷搿o拷锟斤拷址锟斤拷锟斤拷锟� 4.3.2 锟芥本锟叫得碉拷支锟街★拷
cp1252 Windows-1252, 1252 Windows 锟斤拷锟叫碉拷锟斤拷欧锟斤拷锟诫。
KOI8-R koi8-ru, koi8r 锟斤拷锟斤。锟斤拷锟街凤拷锟斤拷锟斤拷 4.3.2 锟芥本锟叫得碉拷支锟街★拷
BIG5 950 锟斤拷锟斤拷锟斤拷锟侥o拷锟斤拷要锟斤拷锟斤拷锟叫癸拷台锟斤拷省锟斤拷
GB2312 936 锟斤拷锟斤拷锟斤拷锟侥o拷锟叫癸拷锟斤拷锟揭憋拷准锟街凤拷锟斤拷锟斤拷
BIG5-HKSCS   锟斤拷锟斤拷锟斤拷锟侥o拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸癸拷锟� Big5 锟街凤拷锟斤拷锟斤拷
Shift_JIS SJIS, 932 锟斤拷锟斤拷
EUC-JP EUCJP 锟斤拷锟斤拷
MacRoman   Mac OS 使锟矫碉拷锟街凤拷锟斤拷锟斤拷
''   An empty string activates detection from script encoding (Zend multibyte), default_charset and current locale (see nl_langinfo() and setlocale()), in this order. Not recommended.

Note: 锟斤拷锟斤拷锟街凤拷锟斤拷没锟斤拷锟较可★拷锟斤拷锟斤拷使锟斤拷默锟较憋拷锟诫并锟阶筹拷锟届常锟斤拷

double_encode

锟截憋拷 double_encode 时锟斤拷PHP 锟斤拷锟斤拷转锟斤拷锟斤拷锟叫碉拷 HTML 实锟藉, 默锟斤拷锟斤拷全锟斤拷转锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟截憋拷锟斤拷锟斤拷锟街凤拷锟斤拷

锟斤拷锟街革拷锟斤拷谋锟斤拷锟� encoding 锟斤, string 锟斤拷锟斤拷锟斤拷锟斤拷效锟侥达拷锟诫单元锟斤拷锟叫o拷 没锟斤拷锟斤拷锟斤拷 ENT_IGNORE 锟斤拷锟斤拷 ENT_SUBSTITUTE 锟斤拷堑锟斤拷锟斤拷锟铰o拷锟结返锟截匡拷锟街凤拷锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.6.0 The default value for the encoding parameter was changed to be the value of the default_charset configuration option.
5.4.0 encoding 锟斤拷锟斤拷锟斤拷默锟斤拷值锟侥筹拷 UTF-8锟斤拷
5.4.0 锟斤拷锟接筹拷锟斤拷 ENT_SUBSTITUTE锟斤拷 ENT_DISALLOWED锟斤拷 ENT_HTML401锟斤拷 ENT_XML1锟斤拷 ENT_XHTML锟斤拷 ENT_HTML5锟斤拷
5.3.0 锟斤拷锟接筹拷锟斤拷 ENT_IGNORE锟斤拷
5.2.3 锟斤拷锟接诧拷锟斤拷 double_encode锟斤拷

锟斤拷锟斤拷

Example #1 htmlentities() 锟斤拷锟斤拷

<?php
$str 
"A 'quote' is <b>bold</b>";

// 锟斤拷锟�: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// 锟斤拷锟�: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($strENT_QUOTES);
?>

Example #2 ENT_IGNORE 锟矫凤拷示锟斤拷

<?php
$str 
"\x8F!!!";

// 锟斤拷锟斤拷锟� string
echo htmlentities($strENT_QUOTES"UTF-8");

// 锟斤拷锟� "!!!"
echo htmlentities($strENT_QUOTES ENT_IGNORE"UTF-8");
?>

锟轿硷拷

  • html_entity_decode() - Convert HTML entities to their corresponding characters
  • get_html_translation_table() - 锟斤拷锟斤拷使锟斤拷 htmlspecialchars 锟斤拷 htmlentities 锟斤拷锟阶拷锟斤拷锟�
  • htmlspecialchars() - 锟斤拷锟斤拷锟斤拷锟街凤拷转锟斤拷为 HTML 实锟斤拷
  • nl2br() - 锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷之前锟斤拷锟斤拷 HTML 锟斤拷锟叫憋拷锟�
  • urlencode() - 锟斤拷锟斤拷 URL 锟街凤拷锟斤拷