1
0
mirror of https://github.com/php/doc-fr.git synced 2026-03-24 07:02:06 +01:00
Files
archived-doc-fr/reference/filter/examples.xml

171 lines
4.8 KiB
XML

<?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
-->