<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>
위의 내용을 포함하여 PHP IP 주소와 정수 변환 주소의 정수 변환을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되길 바랍니다.