-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathexamples.xml
More file actions
171 lines (160 loc) · 4.47 KB
/
examples.xml
File metadata and controls
171 lines (160 loc) · 4.47 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
171
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 627f933cfe6a033dccac32982cd68e7c1b86927f Maintainer: Marqitos 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>Validación</title>
<example>
<title>Validando direcciones de email con <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 "La dirección de email '$email_a' es válida.\n";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "La dirección de email '$email_b' es válida.\n";
} else {
echo "La dirección de email no '$email_b' es válida.\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
La dirección de email 'joe@example.com' es válida.
La dirección de email no 'bogus' es válida.
]]>
</screen>
</example>
<example>
<title>Validando de direcciones IP con <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 "La dirección IP '$ip_a' es válida.";
}
if (filter_var($ip_b, FILTER_VALIDATE_IP)) {
echo "La dirección IP '$ip_b' es válida.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
La dirección IP '127.0.0.1' es válida.
]]>
</screen>
</example>
<example>
<title>Pasando opciones a <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 "El entero A '$int_a' es válido (entre 0 y 3).\n";
}
if (filter_var($int_b, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "El entero B '$int_b' es válido (entre 0 y 3).\n";
}
if (filter_var($int_c, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "El entero C '$int_c' es válido (entre 0 y 3).\n";
}
$options['options']['default'] = 1;
if (($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) !== FALSE) {
echo "El entero C '$int_c' es válido (entre 0 y 3).";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
El entero A '1' es válido (entre 0 y 3).
El entero C '1' es válido (entre 0 y 3).
]]>
</screen>
</example>
</section>
<section xml:id="filter.examples.sanitization">
<title>Saneamiento</title>
<para>
<example>
<title>Saneando y validando direcciones de 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 "Esta dirección de correo saneada (a) es válida.\n";
}
$sanitized_b = filter_var($b, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_b, FILTER_VALIDATE_EMAIL)) {
echo "Esta dirección de correo saneada se considera válida.";
} else {
echo "Esta dirección de correo saneada (b) no es válida.\n";
}
$sanitized_c = filter_var($c, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_c, FILTER_VALIDATE_EMAIL)) {
echo "Esta dirección de correo saneada (c) es válida.\n";
echo "Antes: $c\n";
echo "Después: $sanitized_c\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Esta dirección de correo saneada (a) es válida.
Esta dirección de correo saneada (b) no es válida.
Esta dirección de correo saneada (c) es válida.
Antes: (bogus@example.org)
Despué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
-->