Forum und email
get_html_translation_table

get_html_translation_table

(PHP 4, PHP 5)

get_html_translation_table --  Vrací překladovou tabulku používanou v htmlspecialchars() a htmlentities()

Popis

array get_html_translation_table ( [int table [, int quote_style]] )

get_html_translation_table() vrací překladovou tabulku, která se interně používá ve funkcích htmlspecialchars() a htmlentities(). Dvě nové konstanty (HTML_ENTITIES, HTML_SPECIALCHARS) vám umožňují určit, kterou tabulku chcete. A stejně jako u funkcí htmlspecialchars() a htmlentities() můžete případně určit quote_style se kterým pracujete. Defaultní hodnota je ENT_COMPAT mód. Viz popis těchto módů u htmlspecialchars().

Příklad 1. Ukázka na překladovou tabulku

$trans = get_html_translation_table (HTML_ENTITIES);
$str = "Hallo & <Frau> & Krämer";
$encoded = strtr ($str, $trans);
Proměnná $encoded teď obsahuje: "Hallo &<amp>; &<lt>;Frau&<gt>; &<amp>; Kr&<auml>;mer".

Skvělé je, že pomocí array_flip() můžete změnit směr překladu.

$trans = array_flip ($trans);
$original = strtr ($str, $trans);

Obsahem $original je: "Hallo & <Frau> & Krämer".

Poznámka: Tato funkce byla přidána v PHP 4.0.

Viz také: htmlspecialchars(), htmlentities(), strtr() a array_flip().