2007-12-07 01:18:14 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 09:08:43 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-12-07 01:18:14 +00:00
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.htmlspecialchars" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>htmlspecialchars</refname>
|
|
|
|
<refpurpose>Convert special characters to HTML entities</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
2007-12-29 23:04:24 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-12-07 01:18:14 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>string</type><methodname>htmlspecialchars</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>string</parameter></methodparam>
|
2009-01-16 16:14:26 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>quote_style</parameter><initializer>ENT_COMPAT</initializer></methodparam>
|
2007-12-07 01:18:14 +00:00
|
|
|
<methodparam choice="opt"><type>string</type><parameter>charset</parameter></methodparam>
|
2009-01-16 16:14:26 +00:00
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>double_encode</parameter><initializer>true</initializer></methodparam>
|
2007-12-07 01:18:14 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
Certain characters have special significance in HTML, and should
|
|
|
|
be represented by HTML entities if they are to preserve their
|
|
|
|
meanings. This function returns a string with some of these
|
|
|
|
conversions made; the translations made are those most
|
|
|
|
useful for everyday web programming. If you require all HTML
|
|
|
|
character entities to be translated, use
|
|
|
|
<function>htmlentities</function> instead.
|
|
|
|
</para>
|
|
|
|
<simpara>
|
|
|
|
This function is useful in preventing user-supplied text from
|
|
|
|
containing HTML markup, such as in a message board or guest book
|
2007-12-29 23:04:24 +00:00
|
|
|
application.
|
2007-12-07 01:18:14 +00:00
|
|
|
</simpara>
|
|
|
|
<para>
|
|
|
|
The translations performed are:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'&' (ampersand) becomes '&amp;'
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'"' (double quote) becomes '&quot;' when <constant>ENT_NOQUOTES</constant>
|
|
|
|
is not set.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
''' (single quote) becomes '&#039;' only when
|
|
|
|
<constant>ENT_QUOTES</constant> is set.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'<' (less than) becomes '&lt;'
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'>' (greater than) becomes '&gt;'
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>string</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <type>string</type> being converted.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>quote_style</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The optional second argument, <parameter>quote_style</parameter>, tells
|
|
|
|
the function what to do with single and double quote characters.
|
|
|
|
The default mode, <constant>ENT_COMPAT</constant>, is the backwards compatible mode
|
|
|
|
which only translates the double-quote character and leaves the
|
|
|
|
single-quote untranslated. If <constant>ENT_QUOTES</constant> is set, both single and
|
|
|
|
double quotes are translated and if <constant>ENT_NOQUOTES</constant> is set neither
|
|
|
|
single nor double quotes are translated.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>charset</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2007-12-29 23:04:24 +00:00
|
|
|
Defines character set used in conversion.
|
2007-12-07 01:18:14 +00:00
|
|
|
The default character set is ISO-8859-1.
|
|
|
|
</para>
|
|
|
|
&reference.strings.charsets;
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>double_encode</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When <parameter>double_encode</parameter> is turned off PHP will not
|
|
|
|
encode existing html entities, the default is to convert everything.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-12-29 23:04:24 +00:00
|
|
|
|
2007-12-07 01:18:14 +00:00
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
|
|
|
The converted <type>string</type>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
|
|
|
<para>
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>5.2.3</entry>
|
|
|
|
<entry>
|
|
|
|
The <parameter>double_encode</parameter> parameter was added.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>4.1.0</entry>
|
|
|
|
<entry>
|
|
|
|
The <parameter>charset</parameter> parameter was added.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>htmlspecialchars</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
2003-03-03 18:03:13 +00:00
|
|
|
<?php
|
2002-04-15 00:12:54 +00:00
|
|
|
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
|
2003-03-03 18:03:13 +00:00
|
|
|
echo $new; // <a href='test'>Test</a>
|
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
2007-12-07 01:18:14 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Note that this function does not translate anything beyond what
|
|
|
|
is listed above. For full entity translation, see
|
|
|
|
<function>htmlentities</function>.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
2007-12-29 23:04:24 +00:00
|
|
|
|
2007-12-07 01:18:14 +00:00
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
|
|
|
<member><function>get_html_translation_table</function></member>
|
|
|
|
<member><function>htmlspecialchars_decode</function></member>
|
|
|
|
<member><function>strip_tags</function></member>
|
|
|
|
<member><function>htmlentities</function></member>
|
|
|
|
<member><function>nl2br</function></member>
|
|
|
|
</simplelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
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
|
|
|
|
-->
|