htmlentities
(PHP 4, PHP 5)
htmlentities — Convert all applicable characters to HTML entities
LeÃrás
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().
Paraméterek
- string
-
The input string.
- quote_style
-
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:
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. - charset
-
Like htmlspecialchars(), it takes an optional third argument charset which defines character set used in conversion. Presently, the ISO-8859-1 character set is used as the default.
A következő karakterkészletek a PHP 4.3.0-tól támogatottak.
Támogatott karakterkészletek Karakterkészlet Alias LeÃrás ISO-8859-1 ISO8859-1 Nyugat-Európai (Western European), Latin-1 ISO-8859-15 ISO8859-15 Western European, Latin-9. KiegészÃtve az Euro jellel és a Latin-1(ISO-8859-1)-bÅ‘l hiányzó francia és finn betűkkel. UTF-8 ASCII kompatibilis többájtos 8-bites Unicode. cp866 ibm866, 866 DOS-specifikus cirill karakterkészlet. Ez a karakterkészlet a 4.3.2-ben támogatott. cp1251 Windows-1251, win-1251, 1251 Windows-specifikus cirill karakterkészlet. Ez a karakterkészlet a 4.3.2-ben támogatott. cp1252 Windows-1252, 1252 Windows-specifikus Nyugat-Európai (Western European) karakterkészlet. KOI8-R koi8-ru, koi8r Orosz. Ez a karakterkészlet a 4.3.2-ben támogatott. BIG5 950 Hagyományos kÃnai, fÅ‘képpen Taiwanban használt. GB2312 936 EgyszerűsÃtett kÃnai, nemzeti szabványos karakterkészlet. BIG5-HKSCS Big5 Hong Kong-i kiterjesztésekkel, hagyományos kÃnai. Shift_JIS SJIS, 932 Japán EUC-JP EUCJP Japán Note: Egyéb karakterkészleteket nem ismer fel, helyettük ISO-8859-1 használ.
- double_encode
-
When double_encode is turned off PHP will not encode existing html entities. The default is to convert everything.
Visszatérési értékek
Returns the encoded string.
Változások naplója
Változat | LeÃrás |
---|---|
5.2.3 | The double_encode parameter was added. |
4.1.0 | The charset parameter was added. |
4.0.3 | The quote_style parameter was added. |
Példák
Example#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);
?>