php ip address conversion integer, integer conversion address

WBOY
Release: 2016-07-29 09:09:44
Original
1709 people have browsed it

<code><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);



     <span>$ipVal</span> = <span>$ipArr</span>[<span>0</span>] * <span>0x1000000</span>
            + <span>$ipArr</span>[<span>1</span>] * <span>0x10000</span>
            + <span>$ipArr</span>[<span>2</span>] * <span>0x100</span>
            + <span>$ipArr</span>[<span>3</span>]
            ;

        <span>echo</span><span>$ipVal</span>.<span>'<br/>'</span>;

         <span>$ipArr</span> = <span>array</span>(<span>0</span> => floor( <span>$ipVal</span>/ <span>0x1000000</span>) );

        <span>$ipVint</span>   = <span>$ipVal</span>-(<span>$ipArr</span>[<span>0</span>]*<span>0x1000000</span>); <span>// for clarity</span><span>$ipArr</span>[<span>1</span>] = (<span>$ipVint</span> & <span>0xFF0000</span>)  >> <span>16</span>;

        <span>$ipArr</span>[<span>2</span>] = (<span>$ipVint</span> & <span>0xFF00</span>  )  >> <span>8</span>;

        <span>$ipArr</span>[<span>3</span>] =  <span>$ipVint</span> & <span>0xFF</span>;

        <span>$ipDotted</span> = implode(<span>'.'</span>, <span>$ipArr</span>);

        <span>echo</span><span>$ipDotted</span>;















<span><?php</span><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);
  <span>$ip</span>       = <span>$ipArr</span>[<span>0</span>] * <span>0x1000000</span>
            + <span>$ipArr</span>[<span>1</span>] * <span>0x10000</span>
            + <span>$ipArr</span>[<span>2</span>] * <span>0x100</span>
            + <span>$ipArr</span>[<span>3</span>]
            ;
<span>?></span>This can be written in a bit more efficient way:
<span><?php</span><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);
  <span>$ip</span>       = <span>$ipArr</span>[<span>0</span>]<<<span>24</span>
            + <span>$ipArr</span>[<span>1</span>]<<<span>16</span>
            + <span>$ipArr</span>[<span>2</span>] <<<span>8</span>
            + <span>$ipArr</span>[<span>3</span>]
            ;
<span>?></span>shift is more cheaper.</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the integer conversion of php ip address and integer conversion address, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template