php-doc-en/reference/strings/functions/get-html-translation-table.xml

89 lines
2.9 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
<refentry id="function.get-html-translation-table">
<refnamediv>
<refname>get_html_translation_table</refname>
<refpurpose>
Returns the translation table used by
<function>htmlspecialchars</function> and
<function>htmlentities</function>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>get_html_translation_table</methodname>
<methodparam><type>int</type><parameter>table</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>quote_style</parameter></methodparam>
</methodsynopsis>
<para>
<function>get_html_translation_table</function> will return the
translation table that is used internally for
<function>htmlspecialchars</function> and
<function>htmlentities</function>. There are two new defines
(<parameter>HTML_ENTITIES</parameter>,
<parameter>HTML_SPECIALCHARS</parameter>) that allow you to
specify the table you want. And as in the
<function>htmlspecialchars</function> and
<function>htmlentities</function> functions you can optionally
specify the quote_style you are working with. The default is
ENT_COMPAT mode. See the description of these modes in
<function>htmlspecialchars</function>.
<example>
<title>Translation Table Example</title>
<programlisting role="php">
<![CDATA[
$trans = get_html_translation_table(HTML_ENTITIES);
$str = "Hallo & <Frau> & Kr<4B>mer";
$encoded = strtr($str, $trans);
]]>
</programlisting>
</example>
The <literal>$encoded</literal> variable will now contain:
<literal>"Hallo &amp;amp; &amp;lt;Frau&amp;gt; &amp;amp;
Kr&amp;auml;mer".</literal>
</para>
<para>
The cool thing is using <function>array_flip</function> to change
the direction of the translation.
<informalexample>
<programlisting role="php">
<![CDATA[
$trans = array_flip($trans);
$original = strtr($encoded, $trans);
]]>
</programlisting>
</informalexample>
The content of <literal>$original</literal> would be: "Hallo &amp;
&lt;Frau> &amp; Kr&auml;mer".
</para>
<para>
See also <function>htmlspecialchars</function>,
<function>htmlentities</function>, <function>strtr</function>,
and <function>array_flip</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->