-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathexamples.xml
More file actions
170 lines (160 loc) · 4.76 KB
/
examples.xml
File metadata and controls
170 lines (160 loc) · 4.76 KB
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
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 627f933cfe6a033dccac32982cd68e7c1b86927f Maintainer: yannick Status: ready -->
<!-- Reviewed: no -->
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="filter.examples">
&reftitle.examples;
<section xml:id="filter.examples.validation">
<title>Validation</title>
<example>
<title>Validation d'adresses email avec <function>filter_var</function></title>
<programlisting role="php" xml:id="filter.examples.validation.email">
<![CDATA[
<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "L'adresse email '$email_a' est considérée comme valide.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "L'adresse email '$email_b' est considérée comme valide.";
} else {
echo "L'adresse email '$email_b' est considérée comme invalide.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
L'adresse email 'joe@example.com' est considérée comme valide.
L'adresse email 'bogus' est considérée comme invalide.
]]>
</screen>
</example>
<example>
<title>Validation d'adresses IP avec <function>filter_var</function></title>
<programlisting role="php" xml:id="filter.examples.validation.ip">
<![CDATA[
<?php
$ip_a = '127.0.0.1';
$ip_b = '42.42';
if (filter_var($ip_a, FILTER_VALIDATE_IP)) {
echo "L'adresse IP '$ip_a' est considérée comme valide.";
}
if (filter_var($ip_b, FILTER_VALIDATE_IP)) {
echo "L'adresse IP '$ip_b' est considérée comme valide.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
L'adresse IP '127.0.0.1' est considérée comme valide.
]]>
</screen>
</example>
<example>
<title>Passage d'options à la fonction <function>filter_var</function></title>
<programlisting role="php" xml:id="filter.examples.validation.options">
<![CDATA[
<?php
$int_a = '1';
$int_b = '-1';
$int_c = '4';
$options = array(
'options' => array(
'min_range' => 0,
'max_range' => 3,
)
);
if (filter_var($int_a, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "L'entier A '$int_a' est considéré comme valide (entre 0 et 3).\n";
}
if (filter_var($int_b, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "L'entier B '$int_b' est considéré comme valide (entre 0 et 3).\n";
}
if (filter_var($int_c, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "L'entier C '$int_c' est considéré comme valide (entre 0 et 3).\n";
}
$options['options']['default'] = 1;
if (($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) !== FALSE) {
echo "L'entier C '$int_c' est considéré comme valide (entre 0 et 3).";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
L'entier A '1' est considéré comme valide (entre 0 et 3).
L'entier C '1' est considéré comme valide (entre 0 et 3).
]]>
</screen>
</example>
</section>
<section xml:id="filter.examples.sanitization">
<title>Nettoyage</title>
<para>
<example>
<title>Nettoyage et validation d'adresses email</title>
<programlisting role="php" xml:id="filter.examples.sanitization.email">
<![CDATA[
<?php
$a = 'joe@example.org';
$b = 'bogus - at - example dot org';
$c = '(bogus@example.org)';
$sanitized_a = filter_var($a, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_a, FILTER_VALIDATE_EMAIL)) {
echo "Cette (a) adresse email nettoyée est considérée comme valide.";
}
$sanitized_b = filter_var($b, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_b, FILTER_VALIDATE_EMAIL)) {
echo "Cette (b) adresse email nettoyée est considérée comme valide.";
} else {
echo "Cette (b) adresse email nettoyée est considérée comme invalide.";
}
$sanitized_c = filter_var($c, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_c, FILTER_VALIDATE_EMAIL)) {
echo "Cette (c) adresse email nettoyée est considérée comme valide.";
echo "Avant : $c\n";
echo "Après : $sanitized_c\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Cette (a) adresse email nettoyée est considérée comme valide.
Cette (b) adresse email nettoyée est considérée comme invalide.
Cette (c) adresse email nettoyée est considérée comme valide.
Avant : (bogus@example.org)
Après : bogus@example.org
]]>
</screen>
</example>
</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=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->