/
strip-tags.xml
204 lines (194 loc) · 5.37 KB
/
strip-tags.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.strip-tags" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>strip_tags</refname>
<refpurpose>Strip HTML and PHP tags from a string</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>strip_tags</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>string</type><type>null</type></type><parameter>allowed_tags</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
This function tries to return a string with all NULL bytes, HTML and PHP tags stripped
from a given <parameter>string</parameter>. It uses the same tag stripping
state machine as the <function>fgetss</function> function.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
The input string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>allowed_tags</parameter></term>
<listitem>
<para>
You can use the optional second parameter to specify tags which should
not be stripped.
These are either given as &string;, or as of PHP 7.4.0, as &array;.
Refer to the example below regarding the format of this parameter.
</para>
<note>
<para>
HTML comments and PHP tags are also stripped. This is hardcoded and
can not be changed with <parameter>allowed_tags</parameter>.
</para>
</note>
<note>
<para>
Self-closing XHTML tags are ignored and only non-self-closing tags should be used in
<parameter>allowed_tags</parameter>. For example,
to allow both <literal><br></literal> and
<literal><br/></literal>, you should use:
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
strip_tags($input, '<br>');
?>
]]>
</programlisting>
</informalexample>
</note>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the stripped string.
</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>8.0.0</entry>
<entry>
<parameter>allowed_tags</parameter> is nullable now.
</entry>
</row>
<row>
<entry>7.4.0</entry>
<entry>
The <parameter>allowed_tags</parameter> now alternatively accepts an &array;.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>strip_tags</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
// as of PHP 7.4.0 the line above can be written as:
// echo strip_tags($text, ['p', 'a']);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
This function should not be used to try to prevent XSS attacks.
Use more appropriate functions like <function>htmlspecialchars</function>
or other means depending on the context of the output.
</para>
</warning>
<warning>
<para>
Because <function>strip_tags</function> does not actually validate the
HTML, partial or broken tags can result in the removal of more
text/data than expected.
</para>
</warning>
<warning>
<para>
This function does not modify any attributes on the tags that you allow
using <parameter>allowed_tags</parameter>, including the
<literal>style</literal> and <literal>onmouseover</literal> attributes
that a mischievous user may abuse when posting text that will be shown
to other users.
</para>
</warning>
<note>
<para>
Tag names within the input HTML that are greater than 1023 bytes in length
will be treated as though they are invalid, regardless of the
<parameter>allowed_tags</parameter> parameter.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>htmlspecialchars</function></member>
</simplelist>
</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:"~/.phpdoc/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
-->