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

Tutorial Básico PHP

Tutorial Avançado PHP

PHP & MySQL

Manual de Referência PHP

Uso e exemplo do PHP get_html_translation_table()

   PHP String 字符串函数手册

    A função get_html_translation_table() é usada para retornar a tabela de conversão após o uso de htmlspecialchars() e htmlentities().

Sintaxe

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

Definição e uso

Ele retorna a tabela de conversão usada pelas funções htmlentities() e htmlspecialchars().

Valor retornado

Ele retorna a tabela de conversão como um array, os caracteres originais como chave e as entidades como valor.

Atenção: os caracteres especiais podem ser convertidos de várias maneiras. Por exemplo: " pode ser convertido para ", " ou ". get_html_translation_table() retorna a mais comum delas.

Parâmetro

Número ordinalParâmetros e descrição
1

table(obrigatório)

Esta função contém informações sobre qual tabela retornar HTML_ENTITIES ou HTML_SPECIALCHARS

Possíveis valores:

  • HTML_SPECIALCHARS - 默认。翻译某些需要 URL 编码的字符,以便正确地显示在 HTML 页面上。

  • HTML_ENTITIES - 翻译所有需要 URL 编码的字符,以便正确地显示在 HTML 页面上。

2

flags

可选。指定转换表将包含哪种引号以及转换表用于哪种文档类型。

可用的引号类型:

  • 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 字符串函数手册