PHP代码ip2long 循环有关问题

WBOY
发布: 2016-06-13 12:15:48
原创
1096 人浏览过

PHP代码ip2long 循环问题

print_r($dataIp);<br />            foreach ($dataIp as $key=>$value) {<br />                $data['ip']     =   $value;<br />                $data['iplong']     =   bindec(decbin(ip2long($value)));                            <br />                print_r($data);             <br />            }
登录后复制


打印出来的结果为:
引用
Array
(
[0] => 208.104.70.215
[1] => 74.101.176.171
[2] => 73.17.35.30
[3] => 70.198.197.3
[4] => 46.44.179.76
)
====
Array
(
[ip] => 208.104.70.215
[iplong] => 0
)
Array
(
[ip] => 74.101.176.171
[iplong] => 0
)
Array
(
[ip] => 73.17.35.30
[iplong] => 0
)
Array
(
[ip] => 70.198.197.3
[iplong] => 0
)
Array
(
[ip] => 46.44.179.76
[iplong] => 774681420
)

只有最后一个转换成功了,其他的都失败了,这是什么原因?
------解决思路----------------------
没有问题
Array<br />(<br />    [ip] => 208.104.70.215<br />    [iplong] => 3496494807<br />)<br />Array<br />(<br />    [ip] => 74.101.176.171<br />    [iplong] => 1248178347<br />)<br />Array<br />(<br />    [ip] => 73.17.35.30<br />    [iplong] => 1225859870<br />)<br />Array<br />(<br />    [ip] => 70.198.197.3<br />    [iplong] => 1187431683<br />)<br />Array<br />(<br />    [ip] => 46.44.179.76<br />    [iplong] => 774681420<br />)<br /><br />
登录后复制

但不知你想干什么
------解决思路----------------------
<br /><?php<br />$dataIp = array('208.104.70.215', '74.101.176.171', '73.17.35.30', '70.198.197.3', '46.44.179.76');<br /><br />foreach ($dataIp as $key=>$value) {<br />		$data['ip']     =   $value;<br />		$data['iplong']     =   bindec(decbin(ip2long($value)));                            <br />		print_r($data);             <br />}<br />
登录后复制

输出
<br />Array<br />(<br />    [ip] => 208.104.70.215<br />    [iplong] => 3496494807<br />)<br />Array<br />(<br />    [ip] => 74.101.176.171<br />    [iplong] => 1248178347<br />)<br />Array<br />(<br />    [ip] => 73.17.35.30<br />    [iplong] => 1225859870<br />)<br />Array<br />(<br />    [ip] => 70.198.197.3<br />    [iplong] => 1187431683<br />)<br />Array<br />(<br />    [ip] => 46.44.179.76<br />    [iplong] => 774681420<br />)<br />
登录后复制

也是正常的
------解决思路----------------------
測試過,正常。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板