mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-30 07:48:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78496 c90b9560-bf6c-de11-be94-00142212c4b1
83 lines
2.4 KiB
XML
83 lines
2.4 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.2 $ -->
|
|
<!-- splitted from ./en/functions/network.xml, last change in rev 1.18 -->
|
|
<refentry id="function.ip2long">
|
|
<refnamediv>
|
|
<refname>ip2long</refname>
|
|
<refpurpose>
|
|
Converts a string containing an (IPv4) Internet Protocol dotted address
|
|
into a proper address.
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>ip2long</methodname>
|
|
<methodparam><type>string</type><parameter>ip_address</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
The function <function>ip2long</function> generates an IPv4 Internet
|
|
network address from its Internet standard format (dotted string)
|
|
representation.
|
|
<example>
|
|
<title><function>ip2long</function> Example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname("www.example.com");
|
|
$out = "The following URLs are equivalent:<br>\n";
|
|
$out .= "http://www.example.com/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/<br>\n";
|
|
echo $out;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<note>
|
|
<para>
|
|
Because PHP's integer type is signed, and many IP addresses will
|
|
result in negative integers, you need to use the "%u" formatter of
|
|
<function>sprintf</function> or <function>printf</function> to get
|
|
the string representation of the unsigned IP address.
|
|
</para>
|
|
</note>
|
|
This second example shows how to print a converted address with the
|
|
<function>printf</function> function :
|
|
<example>
|
|
<title>Displaying an IP address</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ip = gethostbyname("www.example.com");
|
|
printf("%u\n", ip2long($ip));
|
|
echo $out;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
See also: <function>long2ip</function>
|
|
</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
|
|
-->
|