English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial di base PHP

Tutorial avanzato PHP

PHP & MySQL

Manuale di riferimento PHP

Uso e esempio della funzione PHP get_html_translation_table()

   PHP String 字符串函数手册

    La funzione get_html_translation_table() viene utilizzata per restituire la tabella di conversione dopo l'uso di htmlspecialchars() e htmlentities().

Sintassi

array get_html_translation_table ([ int $table = HTML_SPECIALCHARS [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = "UTF-8" ]]] )

Definizione e uso

Restituisce la tabella di conversione utilizzata dalle funzioni htmlentities() e htmlspecialchars().

Valore di ritorno

Restituisce la tabella di conversione come array, con i caratteri originali come chiave e le entità come valore.

Attenzione: i caratteri speciali possono essere convertiti in diversi modi. Ad esempio: " può essere convertito in ", " o ". La funzione get_html_translation_table() restituisce il più comune.

Parametro

Numero di ordinamentoParametri e descrizione
1

table (obbligatorio)

Contiene informazioni su quale tabella HTML_ENTITIES o HTML_SPECIALCHARS viene restituita.

Valori possibili:

  • HTML_SPECIALCHARS - Predefinito. Traduce alcuni caratteri necessari per l'encoding URL, in modo che possano essere visualizzati correttamente nella pagina HTML.

  • HTML_ENTITIES - Traduce tutti i caratteri necessari per l'encoding URL, in modo che possano essere visualizzati correttamente nella pagina HTML.

2

flags

Opzionale. Specifica quale tipo di virgolette la tabella di conversione deve includere e per quale tipo di documento viene utilizzata la tabella di conversione.

可用的引号类型:

  • ENT_COMPAT - 默认。转换表包含双引号实体,不包含单引号实体。

  • ENT_QUOTES - 转换表包含双引号实体和单引号实体。

  • ENT_NOQUOTES - 转换表不包含双引号实体和单引号实体。

指定转换表适用的文档类型的附加 flags:

  • ENT_HTML401 - 默认。HTML 4.01 的转换表。

  • ENT_HTML5 - HTML 5 的转换表。

  • ENT_XML1 - XML 1 的转换表。

  • ENT_XHTML - XHTML 的转换表。

3

encoding

可选。一个指定了要使用的字符集的字符串。

允许的值:

  • UTF-8 - 默认。ASCII 兼容多字节的 8 位 Unicode

  • ISO-8859-1 - 西欧

  • ISO-8859-15 - 西欧(加入欧元符号 + ISO-8859-1 中丢失的法语和芬兰语字母)

  • cp866 - DOS 专用 Cyrillic 字符集

  • cp1251 - Windows 专用 Cyrillic 字符集

  • cp1252 - Windows 专用西欧字符集

  • KOI8-R - 俄语

  • BIG5 - 繁体中文,主要在台湾使用

  • GB2312 - 简体中文,国家标准字符集

  • BIG5-HKSCS - 带香港扩展的 Big5

  • Shift_JIS - 日语

  • EUC-JP - 日语

  • MacRoman - Mac 操作系统使用的字符集

注释:在 PHP 5.4 更早版本,无法被识别的字符集将被忽略并由 ISO-8859-1 代替。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 代替。

在线示例

试试下面的实例,使用 HTML_SPECIALCHARS 的转换表:

<?php
   //使用 HTML_SPECIALCHARS 的转换表
   print_r (get_html_translation_table(HTML_SPECIALCHARS));
?>
测试看看‹/›

输出结果

Array
(
   ["] => "
   [&] => &
   [<] => <
   [>] => >>
)

PHP String 字符串函数手册