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

����һ��λ�����ǣ�����������δ������š���Ч�������С�ʹ���ĵ������͡� Ĭ���� ENT_COMPAT | ENT_HTML401��

��Ч flags ��dz���
������ ����
ENT_COMPAT ��ת��˫���ţ���ת�������š�
ENT_QUOTES ��ת��˫����Ҳת�������š�
ENT_NOQUOTES ��/˫���Ŷ���ת��
ENT_IGNORE ��Ĭ������Ч�Ĵ��뵥Ԫ���У������Ƿ��ؿ��ַ����� ������ʹ�ô˱�ǣ� ��Ϊ��» �����а�ȫӰ����
ENT_SUBSTITUTE �滻��Ч�Ĵ��뵥Ԫ����Ϊ Unicode �������Replacement Character���� U+FFFD (UTF-8) ���� � (����)�������Ƿ��ؿ��ַ�����
ENT_DISALLOWED Ϊ�ĵ�����Ч������滻Ϊ Unicode �������Replacement 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������ŷԪ���ţ�����ͷ�������ĸ�� Latin-1(ISO-8859-1) ��ȱʧ��
UTF-8   ASCII ���ݵĶ��ֽ� 8 λ Unicode��
cp866 ibm866, 866 DOS ���е���������롣���ַ����� 4.3.2 �汾�еõ�֧�֡�
cp1251 Windows-1251, win-1251, 1251 Windows ���е���������롣���ַ����� 4.3.2 �汾�еõ�֧�֡�
cp1252 Windows-1252, 1252 Windows ���е���ŷ���롣
KOI8-R koi8-ru, koi8r ������ַ����� 4.3.2 �汾�еõ�֧�֡�
BIG5 950 �������ģ���Ҫ�����й�̨��ʡ��
GB2312 936 �������ģ��й����ұ�׼�ַ�����
BIG5-HKSCS   �������ģ����������չ�� 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 ��������Ч�Ĵ��뵥Ԫ���У� û������ ENT_IGNORE ���� ENT_SUBSTITUTE ��ǵ�����£��᷵�ؿ��ַ�����

������־

�汾 ˵��
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 ������Ĭ��ֵ�ij� 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");
?>

�μ�