-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathexamples.xml
More file actions
171 lines (160 loc) · 4.85 KB
/
examples.xml
File metadata and controls
171 lines (160 loc) · 4.85 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: takagi Status: ready -->
<!-- Credits: mumumu -->
<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>検証</title>
<example>
<title><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 "'$email_a' はメールアドレスとして有効です。\n";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "'$email_b' はメールアドレスとして有効です。\n";
} else {
echo "'$email_b' はメールアドレスとして無効です。\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
'joe@example.com' はメールアドレスとして有効です。
'bogus' はメールアドレスとして無効です。
]]>
</screen>
</example>
<example>
<title><function>filter_var</function> での IP アドレスの検証</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 "'$ip_a' は IP アドレスとして有効です。";
}
if (filter_var($ip_b, FILTER_VALIDATE_IP)) {
echo "'$ip_b' は IP アドレスとして有効です。";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
'127.0.0.1' は IP アドレスとして有効です。
]]>
</screen>
</example>
<example>
<title><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 "整数値 A '$int_a' は有効な値 (0 から 3 までの間) です。\n";
}
if (filter_var($int_b, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "整数値 B '$int_b' は有効な値 (0 から 3 までの間) です。\n";
}
if (filter_var($int_c, FILTER_VALIDATE_INT, $options) !== FALSE) {
echo "整数値 C '$int_c' は有効な値 (0 から 3 までの間) です。\n";
}
$options['options']['default'] = 1;
if (($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) !== FALSE) {
echo "整数値 C '$int_c' は有効な値 (0 から 3 までの間) です。";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
整数値 A '1' は有効な値 (0 から 3 までの間) です。
整数値 C '1' は有効な値 (0 から 3 までの間) です。
]]>
</screen>
</example>
</section>
<section xml:id="filter.examples.sanitization">
<title>除去</title>
<para>
<example>
<title>メールアドレスの検証、および不正な部分の除去</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 "処理済の (a) はメールアドレスとして有効です。\n";
}
$sanitized_b = filter_var($b, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_b, FILTER_VALIDATE_EMAIL)) {
echo "処理済のメールアドレスは有効です。";
} else {
echo "処理済の (b) はメールアドレスとして無効です。\n";
}
$sanitized_c = filter_var($c, FILTER_SANITIZE_EMAIL);
if (filter_var($sanitized_c, FILTER_VALIDATE_EMAIL)) {
echo "処理済の (c) はメールアドレスとして有効です。\n";
echo "処理前: $c\n";
echo "処理後: $sanitized_c\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
処理済の (a) はメールアドレスとして有効です。
処理済の (b) はメールアドレスとして無効です。
処理済の (c) はメールアドレスとして有効です。
処理前: (bogus@example.org)
処理後: 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
-->