/
filters.xml
659 lines (649 loc) · 20.9 KB
/
filters.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="filter.filters" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Types of filters</title>
<!--Validate filters: {{{-->
<section xml:id="filter.filters.validate">
<title>Validate filters</title>
<para>
<table>
<title>Listing of filters for validation</title>
<tgroup cols="5">
<thead>
<row>
<entry>ID</entry>
<entry>Name</entry>
<entry>Options</entry>
<entry>Flags</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>FILTER_VALIDATE_BOOLEAN</constant></entry>
<entry>"boolean"</entry>
<entry>
<parameter>default</parameter>
</entry>
<entry>
<constant>FILTER_NULL_ON_FAILURE</constant>
</entry>
<entry>
<para>
Returns &true; for "1", "true", "on" and "yes".
Returns &false; otherwise.
</para>
<para>
If <constant>FILTER_NULL_ON_FAILURE</constant> is set, &false; is
returned only for "0", "false", "off", "no", and "", and
&null; is returned for all non-boolean values.
</para>
</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_EMAIL</constant></entry>
<entry>"validate_email"</entry>
<entry>
<parameter>default</parameter>
</entry>
<entry></entry>
<entry>
<para>
Validates whether the value is a valid e-mail address.
</para>
<para>
In general, this validates e-mail addresses against the syntax in
RFC 822, with the exceptions that comments and whitespace folding
are not supported.
</para>
</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_FLOAT</constant></entry>
<entry>"float"</entry>
<entry>
<parameter>default</parameter>,
<parameter>decimal</parameter>
</entry>
<entry>
<constant>FILTER_FLAG_ALLOW_THOUSAND</constant>
</entry>
<entry>Validates value as float, and converts to float on success.</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_INT</constant></entry>
<entry>"int"</entry>
<entry>
<parameter>default</parameter>,
<parameter>min_range</parameter>,
<parameter>max_range</parameter>
</entry>
<entry>
<constant>FILTER_FLAG_ALLOW_OCTAL</constant>,
<constant>FILTER_FLAG_ALLOW_HEX</constant>
</entry>
<entry>Validates value as integer, optionally from the specified range, and converts to int on success.</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_IP</constant></entry>
<entry>"validate_ip"</entry>
<entry>
<parameter>default</parameter>
</entry>
<entry>
<constant>FILTER_FLAG_IPV4</constant>,
<constant>FILTER_FLAG_IPV6</constant>,
<constant>FILTER_FLAG_NO_PRIV_RANGE</constant>,
<constant>FILTER_FLAG_NO_RES_RANGE</constant>
</entry>
<entry>
Validates value as IP address, optionally only IPv4 or IPv6 or not
from private or reserved ranges.
</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_MAC</constant></entry>
<entry>"validate_mac_address"</entry>
<entry>
<parameter>default</parameter>
</entry>
<entry></entry>
<entry>Validates value as MAC address.</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_REGEXP</constant></entry>
<entry>"validate_regexp"</entry>
<entry>
<parameter>default</parameter>,
<parameter>regexp</parameter>
</entry>
<entry></entry>
<entry>
Validates value against <parameter>regexp</parameter>, a
<link linkend="book.pcre">Perl-compatible</link> regular expression.
</entry>
</row>
<row>
<entry><constant>FILTER_VALIDATE_URL</constant></entry>
<entry>"validate_url"</entry>
<entry>
<parameter>default</parameter>
</entry>
<entry>
<constant>FILTER_FLAG_PATH_REQUIRED</constant>,
<constant>FILTER_FLAG_QUERY_REQUIRED</constant>
</entry>
<entry>Validates value as URL (according to <link xlink:href="&url.rfc;2396">&url.rfc;2396</link>), optionally with required components. Beware a valid URL may not specify the HTTP protocol <literal>http://</literal> so further validation may be required to determine the URL uses an expected protocol, e.g. <literal>ssh://</literal> or <literal>mailto:</literal>. Note that the function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<note>
<para>
As of PHP 5.4.11, the numbers +0 and -0 validate as both integers as well
as floats (using <constant>FILTER_VALIDATE_FLOAT</constant> and
<constant>FILTER_VALIDATE_INT</constant>). Before PHP 5.4.11 they only
validated as floats (using <constant>FILTER_VALIDATE_FLOAT</constant>).
</para>
<para>
When <parameter>default</parameter> is set to option, <parameter>default</parameter>'s value is used if value is not validated.
</para>
</note>
<simplesect role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.5.0</entry>
<entry>
Added <constant>FILTER_VALIDATE_MAC</constant>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</simplesect>
</section>
<!--}}}-->
<!-- Sanitize filters: {{{-->
<section xml:id="filter.filters.sanitize">
<title>Sanitize filters</title>
<para>
<table>
<title>List of filters for sanitization</title>
<tgroup cols="5">
<thead>
<row>
<entry>ID</entry>
<entry>Name</entry>
<entry>Flags</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>FILTER_SANITIZE_EMAIL</constant></entry>
<entry>"email"</entry>
<entry></entry>
<entry>
Remove all characters except letters, digits and
<literal>!#$%&'*+-=?^_`{|}~@.[]</literal>.
</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_ENCODED</constant></entry>
<entry>"encoded"</entry>
<entry>
<constant>FILTER_FLAG_STRIP_LOW</constant>,
<constant>FILTER_FLAG_STRIP_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_LOW</constant>,
<constant>FILTER_FLAG_ENCODE_HIGH</constant>
</entry>
<entry>URL-encode string, optionally strip or encode special characters.</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_MAGIC_QUOTES</constant></entry>
<entry>"magic_quotes"</entry>
<entry></entry>
<entry>Apply <function>addslashes</function>.</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_NUMBER_FLOAT</constant></entry>
<entry>"number_float"</entry>
<entry>
<constant>FILTER_FLAG_ALLOW_FRACTION</constant>,
<constant>FILTER_FLAG_ALLOW_THOUSAND</constant>,
<constant>FILTER_FLAG_ALLOW_SCIENTIFIC</constant>
</entry>
<entry>
Remove all characters except digits, <literal>+-</literal> and
optionally <literal>.,eE</literal>.
</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_NUMBER_INT</constant></entry>
<entry>"number_int"</entry>
<entry></entry>
<entry>
Remove all characters except digits, plus and minus sign.
</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_SPECIAL_CHARS</constant></entry>
<entry>"special_chars"</entry>
<entry>
<constant>FILTER_FLAG_STRIP_LOW</constant>,
<constant>FILTER_FLAG_STRIP_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_HIGH</constant>
</entry>
<entry>
HTML-escape <literal>'"<>&</literal> and characters with
ASCII value less than 32, optionally strip or encode other special
characters.
</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_FULL_SPECIAL_CHARS</constant></entry>
<entry>"full_special_chars"</entry>
<entry>
<constant>FILTER_FLAG_NO_ENCODE_QUOTES</constant>,
</entry>
<entry>
Equivalent to calling <function>htmlspecialchars</function> with <constant>ENT_QUOTES</constant> set. Encoding quotes can
be disabled by setting <constant>FILTER_FLAG_NO_ENCODE_QUOTES</constant>. Like <function>htmlspecialchars</function>, this
filter is aware of the <link linkend="ini.default-charset">default_charset</link> and if a sequence of bytes is detected that
makes up an invalid character in the current character set then the entire string is rejected resulting in a 0-length string.
When using this filter as a default filter, see the warning below about setting the default flags to 0.
</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_STRING</constant></entry>
<entry>"string"</entry>
<entry>
<constant>FILTER_FLAG_NO_ENCODE_QUOTES</constant>,
<constant>FILTER_FLAG_STRIP_LOW</constant>,
<constant>FILTER_FLAG_STRIP_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_LOW</constant>,
<constant>FILTER_FLAG_ENCODE_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_AMP</constant>
</entry>
<entry>Strip tags, optionally strip or encode special characters.</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_STRIPPED</constant></entry>
<entry>"stripped"</entry>
<entry></entry>
<entry>Alias of "string" filter.</entry>
</row>
<row>
<entry><constant>FILTER_SANITIZE_URL</constant></entry>
<entry>"url"</entry>
<entry></entry>
<entry>
Remove all characters except letters, digits and
<literal>$-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=</literal>.
</entry>
</row>
<row>
<entry><constant>FILTER_UNSAFE_RAW</constant></entry>
<entry>"unsafe_raw"</entry>
<entry>
<constant>FILTER_FLAG_STRIP_LOW</constant>,
<constant>FILTER_FLAG_STRIP_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_LOW</constant>,
<constant>FILTER_FLAG_ENCODE_HIGH</constant>,
<constant>FILTER_FLAG_ENCODE_AMP</constant>
</entry>
<entry>
Do nothing, optionally strip or encode special characters. This
filter is also aliased to <constant>FILTER_DEFAULT</constant>.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<warning>
<para>
When using one of these filters as a default filter either through your ini file
or through your web server's configuration, the default flags is set to
<constant>FILTER_FLAG_NO_ENCODE_QUOTES</constant>. You need to explicitly set
filter.default_flags to 0 to have quotes encoded by default. Like this:
<example>
<title>Configuring the default filter to act like htmlspecialchars</title>
<programlisting role="php">
<![CDATA[
filter.default = full_special_chars
filter.default_flags = 0
]]>
</programlisting>
</example>
</para>
</warning>
<simplesect role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.2.11/5.3.1</entry>
<entry>
Slashes (<literal>/</literal>) are removed by
<constant>FILTER_SANITIZE_EMAIL</constant>. Prior they were retained.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</simplesect>
</section>
<!--}}}-->
<!-- Other filters: {{{-->
<section xml:id="filter.filters.misc">
<title>Other filters</title>
<para>
<table>
<title>List of miscellaneous filters</title>
<tgroup cols="5">
<thead>
<row>
<entry>ID</entry>
<entry>Name</entry>
<entry>Options</entry>
<entry>Flags</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>FILTER_CALLBACK</constant></entry>
<entry>"callback"</entry>
<entry><type>callable</type> function or method</entry>
<entry></entry>
<entry>Call user-defined function to filter data.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</section>
<!--}}}-->
<!-- Filter flags: {{{-->
<section xml:id="filter.filters.flags">
<title>Filter flags</title>
<para>
<table>
<title>List of filter flags</title>
<tgroup cols="3">
<thead>
<row>
<entry>ID</entry>
<entry>Used with</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>FILTER_FLAG_STRIP_LOW</constant></entry>
<entry>
<constant>FILTER_SANITIZE_ENCODED</constant>,
<constant>FILTER_SANITIZE_SPECIAL_CHARS</constant>,
<constant>FILTER_SANITIZE_STRING</constant>,
<constant>FILTER_UNSAFE_RAW</constant>
</entry>
<entry>
Strips characters that have a numerical value <32.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_STRIP_HIGH</constant></entry>
<entry>
<constant>FILTER_SANITIZE_ENCODED</constant>,
<constant>FILTER_SANITIZE_SPECIAL_CHARS</constant>,
<constant>FILTER_SANITIZE_STRING</constant>,
<constant>FILTER_UNSAFE_RAW</constant>
</entry>
<entry>
Strips characters that have a numerical value >127.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ALLOW_FRACTION</constant></entry>
<entry>
<constant>FILTER_SANITIZE_NUMBER_FLOAT</constant>
</entry>
<entry>
Allows a period (<literal>.</literal>) as a fractional separator in
numbers.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ALLOW_THOUSAND</constant></entry>
<entry>
<constant>FILTER_SANITIZE_NUMBER_FLOAT</constant>,
<constant>FILTER_VALIDATE_FLOAT</constant>
</entry>
<entry>
Allows a comma (<literal>,</literal>) as a thousands separator in
numbers.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ALLOW_SCIENTIFIC</constant></entry>
<entry>
<constant>FILTER_SANITIZE_NUMBER_FLOAT</constant>
</entry>
<entry>
Allows an <literal>e</literal> or <literal>E</literal> for scientific
notation in numbers.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_NO_ENCODE_QUOTES</constant></entry>
<entry>
<constant>FILTER_SANITIZE_STRING</constant>
</entry>
<entry>
If this flag is present, single (<literal>'</literal>) and double
(<literal>"</literal>) quotes will not be encoded.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ENCODE_LOW</constant></entry>
<entry>
<constant>FILTER_SANITIZE_ENCODED</constant>,
<constant>FILTER_SANITIZE_STRING</constant>,
<constant>FILTER_SANITIZE_RAW</constant>
</entry>
<entry>
Encodes all characters with a numerical value <32.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ENCODE_HIGH</constant></entry>
<entry>
<constant>FILTER_SANITIZE_ENCODED</constant>,
<constant>FILTER_SANITIZE_SPECIAL_CHARS</constant>,
<constant>FILTER_SANITIZE_STRING</constant>,
<constant>FILTER_SANITIZE_RAW</constant>
</entry>
<entry>
Encodes all characters with a numerical value >127.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ENCODE_AMP</constant></entry>
<entry>
<constant>FILTER_SANITIZE_STRING</constant>,
<constant>FILTER_SANITIZE_RAW</constant>
</entry>
<entry>
Encodes ampersands (<literal>&</literal>).
</entry>
</row>
<row>
<entry><constant>FILTER_NULL_ON_FAILURE</constant></entry>
<entry>
<constant>FILTER_VALIDATE_BOOLEAN</constant>
</entry>
<entry>
Returns &null; for unrecognized boolean values.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ALLOW_OCTAL</constant></entry>
<entry>
<constant>FILTER_VALIDATE_INT</constant>
</entry>
<entry>
Regards inputs starting with a zero (<literal>0</literal>) as octal
numbers. This only allows the succeeding digits to be
<literal>0-7</literal>.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_ALLOW_HEX</constant></entry>
<entry>
<constant>FILTER_VALIDATE_INT</constant>
</entry>
<entry>
Regards inputs starting with <literal>0x</literal> or
<literal>0X</literal> as hexadecimal numbers. This only allows
succeeding characters to be <literal>a-fA-F0-9</literal>.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_IPV4</constant></entry>
<entry>
<constant>FILTER_VALIDATE_IP</constant>
</entry>
<entry>
Allows the IP address to be in IPv4 format.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_IPV6</constant></entry>
<entry>
<constant>FILTER_VALIDATE_IP</constant>
</entry>
<entry>
Allows the IP address to be in IPv6 format.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_NO_PRIV_RANGE</constant></entry>
<entry>
<constant>FILTER_VALIDATE_IP</constant>
</entry>
<entry>
<para>
Fails validation for the following private IPv4 ranges:
<literal>10.0.0.0/8</literal>, <literal>172.16.0.0/12</literal> and
<literal>192.168.0.0/16</literal>.
</para>
<para>
Fails validation for the IPv6 addresses starting with
<literal>FD</literal> or <literal>FC</literal>.
</para>
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_NO_RES_RANGE</constant></entry>
<entry>
<constant>FILTER_VALIDATE_IP</constant>
</entry>
<entry>
Fails validation for the following reserved IPv4 ranges:
<literal>0.0.0.0/8</literal>, <literal>169.254.0.0/16</literal>,
<literal>192.0.2.0/24</literal> and <literal>224.0.0.0/4</literal>.
This flag does not apply to IPv6 addresses.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_PATH_REQUIRED</constant></entry>
<entry>
<constant>FILTER_VALIDATE_URL</constant>
</entry>
<entry>
Requires the <acronym>URL</acronym> to contain a path part.
</entry>
</row>
<row>
<entry><constant>FILTER_FLAG_QUERY_REQUIRED</constant></entry>
<entry>
<constant>FILTER_VALIDATE_URL</constant>
</entry>
<entry>
Requires the <acronym>URL</acronym> to contain a query string.
</entry>
</row>
<row>
<entry><constant>FILTER_REQUIRE_SCALAR</constant></entry>
<entry>
</entry>
<entry>
Requires the value to be scalar.
</entry>
</row>
<row>
<entry><constant>FILTER_REQUIRE_ARRAY</constant></entry>
<entry>
</entry>
<entry>
Requires the value to be an array.
</entry>
</row>
<row>
<entry><constant>FILTER_FORCE_ARRAY</constant></entry>
<entry>
</entry>
<entry>
If the value is a scalar, it is treated as array with the scalar value
as only element.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</section>
<!--}}}-->
</chapter>
<!-- 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=marker fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->