mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
145 lines
4.0 KiB
XML
145 lines
4.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 184f3f7bd45643cb80f828d0bb001991ec3a5fad Maintainer: leonardolara Status: ready -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="function.ip2long">
|
|
<refnamediv>
|
|
<refname>ip2long</refname>
|
|
<refpurpose>Converte uma string contendo um endereço com pontos do protocolo da Internet (IPv4) em um número inteiro longo</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>int</type><type>false</type></type><methodname>ip2long</methodname>
|
|
<methodparam><type>string</type><parameter>ip</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
A função <function>ip2long</function> gera uma representação inteira longa
|
|
do endereço de rede da Internet IPv4 a partir de sua representação no
|
|
formato padrão da Internet (string com pontos).
|
|
</para>
|
|
<para>
|
|
<function>ip2long</function> também funcionará com endereços IP
|
|
incompletos. Leia <link xlink:href="&url.ip2long.tech;">&url.ip2long.tech;</link>
|
|
para mais informações.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>ip</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Um endereço no formato padrão.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna o número inteiro longo ou &false; se <parameter>ip</parameter>
|
|
for inválido.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>ip2long</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname('www.example.com');
|
|
$out = "Os seguintes URLs são equivalentes:<br />\n";
|
|
$out .= 'http://www.example.com/, http://' . $ip . '/, e http://' . sprintf("%u", ip2long($ip)) . "/<br />\n";
|
|
echo $out;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exibindo um endereço IP</title>
|
|
<para>
|
|
Este segundo exemplo mostra como exibir um endereço convertido com
|
|
a função <function>printf</function>:
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname('www.example.com');
|
|
$long = ip2long($ip);
|
|
|
|
if ($long == -1 || $long === FALSE) {
|
|
echo 'IP inválido, tente novamente';
|
|
} else {
|
|
echo $ip . "\n"; // 192.0.34.166
|
|
echo $long . "\n"; // 3221234342 (-1073732954 em sistemas de 32 bits, devido ao estouro de número inteiro)
|
|
printf("%u\n", ip2long($ip)); // 3221234342
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Como o tipo <type>int</type> do PHP é com sinal e muitos endereços IP
|
|
resultarão em números inteiros negativos em arquiteturas de 32 bits, é necessário usar
|
|
o formatador "%u" de <function>sprintf</function> ou
|
|
<function>printf</function> para obter a representação em string do
|
|
endereço IP sem sinal.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<function>ip2long</function> retornará <literal>-1</literal> para o IP
|
|
<literal>255.255.255.255</literal> em sistemas de 32 bits devido ao estouro do valor inteiro.
|
|
</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:"~/.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
|
|
-->
|