get_html_translation_table
(PHP 4, PHP 5, PHP 7, PHP 8)
get_html_translation_table — 返回使用 htmlspecialchars() 和 htmlentities() 后的轉換表
說明
$table
= HTML_SPECIALCHARS, int $flags
= ENT_COMPAT | ENT_HTML401, string $encoding
= 'UTF-8'): arrayget_html_translation_table() 將返回 htmlspecialchars() 和 htmlentities() 處理后的轉換表。
注意:
特殊字元可以使用多種轉換方式。 例如:
"
可以被轉換成"
,"
或者"
. get_html_translation_table() 返回其中最常用的。
參數
-
table
-
有兩個新的常量 (
HTML_ENTITIES
,HTML_SPECIALCHARS
) 允許你指定你想要的表。 -
flags
-
A bitmask of one or more of the following flags, which specify which quotes the table will contain as well as which document type the table is for. The default is
ENT_COMPAT | ENT_HTML401
.Available flags
constantsConstant Name Description ENT_COMPAT
Table will contain entities for double-quotes, but not for single-quotes. ENT_QUOTES
Table will contain entities for both double and single quotes. ENT_NOQUOTES
Table will neither contain entities for single quotes nor for double quotes. ENT_HTML401
Table for HTML 4.01. ENT_XML1
Table for XML 1. ENT_XHTML
Table for XHTML. ENT_HTML5
Table for HTML 5. -
encoding
-
Encoding to use. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards.
支援以下字符集:
支援的字符集列表 字符集 別名 描述 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. 注意: 其他字符集沒有認可。將會使用預設編碼並拋出異常。
返回值
將轉換表作為一個陣列返回。
更新日誌
版本 | 說明 |
---|---|
5.4.0 |
The default value for the encoding parameter was
changed to UTF-8.
|
5.4.0 |
The constants ENT_HTML401 , ENT_XML1 ,
ENT_XHTML and ENT_HTML5 were added.
|
5.3.4 |
The encoding parameter was added.
|
範例
示例 #1 Translation Table Example
<?php
var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5));
?>
以上例程的輸出類似於:
array(1510) { [" "]=> string(9) "
" ["!"]=> string(6) "!" ["""]=> string(6) """ ["#"]=> string(5) "#" ["$"]=> string(8) "$" ["%"]=> string(8) "%" ["&"]=> string(5) "&" ["'"]=> string(6) "'" // ... }
參見
- htmlspecialchars() - 將特殊字元轉換為 HTML 實體
- htmlentities() - 將字元轉換為 HTML 轉義字元
- html_entity_decode() - Convert HTML entities to their corresponding characters