mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-04-25 09:38:03 +02:00
5b28044a8f
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@259835 c90b9560-bf6c-de11-be94-00142212c4b1
192 lines
5.0 KiB
XML
192 lines
5.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.20 $ -->
|
|
<!-- EN-Revision: 1.17 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
|
|
<refentry xml:id="function.ip2long" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>ip2long</refname>
|
|
<refpurpose>Convertit une chaîne contenant une adresse (IPv4) IP numérique en adresse littérale</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>ip2long</methodname>
|
|
<methodparam><type>string</type><parameter>ip_address</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Génère une adresse IPv4 à partir de son équivalent numérique.
|
|
</para>
|
|
<para>
|
|
<function>ip2long</function> fonctionne également avec des adresses IP
|
|
incomplètes. Lisez <link xlink:href="&url.ip2long.tech;">&url.ip2long.tech;</link>
|
|
pour plus d'informations.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>ip_address</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Une adresse au format standard.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne une adresse IPv4, ou &false; si <parameter>ip_address</parameter>
|
|
est invalide.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.0.0</entry>
|
|
<entry>
|
|
Avant cette version, <function>ip2long</function> retournait -1 en cas d'échec.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>ip2long</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname('www.example.com');
|
|
$out = "Les URLS suivantes sont équivalentes :<br />\n";
|
|
$out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", ip2long($ip)) . "/<br />\n";
|
|
echo $out;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Affichage d'une adresse IP</title>
|
|
<para>
|
|
Ce second exemple montre comment afficher une adresse convertie
|
|
à l'aide de la fonction <function>printf</function> en PHP 4 et en PHP 5 :
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname('www.example.com');
|
|
$long = ip2long($ip);
|
|
|
|
if ($long == -1 || $long === FALSE) {
|
|
echo 'IP invalide, merci d\'essayer encore';
|
|
} else {
|
|
echo $ip . "\n"; // 192.0.34.166
|
|
echo $long . "\n"; // -1073732954
|
|
printf("%u\n", ip2long($ip)); // 3221234342
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Validation d'adresse IP</title>
|
|
<para>
|
|
<function>ip2long</function> ne devrait pas être utilisée comme seule
|
|
méthode pour valider une adresse IP. Combinez-la avec <function>long2ip</function> :
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// s'assure que les IPs sont valides. Convertit également une IP incomplète
|
|
// en un format valide comme expliqué plus haut.
|
|
$ip = long2ip(ip2long("127.0.0.1")); // "127.0.0.1"
|
|
$ip = long2ip(ip2long("10.0.0")); // "10.0.0.0"
|
|
$ip = long2ip(ip2long("10.0.256")); // "10.0.1.0"
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Comme les entiers PHP sont signés et que beaucoup d'adresses IP
|
|
peuvent être des entiers négatifs, vous devez utiliser
|
|
le formateur "%u" de la fonction
|
|
<function>sprintf</function> ou <function>printf</function>
|
|
pour récupérer une représentation sous la forme d'une chaîne de caractères
|
|
pour les adresses IP non signées.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<function>ip2long</function> devrait retourner &false; pour l'adresse IP
|
|
<literal>255.255.255.255</literal> en PHP 5 <= 5.0.2. Ce comportement
|
|
a été modifié en PHP 5.0.3 où il retournait <literal>-1</literal> (comme en PHP 4).
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>long2ip</function></member>
|
|
<member><function>sprintf</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- 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:"../../../../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
|
|
--> |