(PHP 4, PHP 5)
htmlentities — Convert all applicable characters to HTML entities
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().
The input string.
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:
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. |
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.
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.
When double_encode is turned off PHP will not encode existing html entities. The default is to convert everything.
Returns the encoded string.
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. |
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);
?>