首頁 > 後端開發 > php教程 > php ip位址轉換整數,整數轉換位址

php ip位址轉換整數,整數轉換位址

WBOY
發布: 2016-07-29 09:09:44
原創
1729 人瀏覽過

<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>
登入後複製
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了php ip位址轉換整數,整數轉換位址,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板