问题描述
- PHP代码ip2long 循环问题
-
代码:print_r($dataIp); foreach ($dataIp as $key=>$value) { $data['ip'] = $value; $data['iplong'] = bindec(decbin(ip2long($value))); print_r($data); }
显示结果
Array
(
[0] => 208.104.70.215
[1] => 74.101.176.171
[2] => 73.17.35.30
[3] => 70.198.197.3
[4] => 162.226.184.30
[5] => 142.167.132.139
[6] => 69.204.125.71
[7] => 76.77.139.72
[8] => 50.82.236.23
[9] => 68.197.139.155
[10] => 188.29.165.19
[11] => 92.14.251.192
[12] => 122.151.11.144
[13] => 2.122.114.91
[14] => 31.100.182.110
[15] => 199.7.157.11
[16] => 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] => 162.226.184.30
[iplong] => 0
)
Array
(
[ip] => 142.167.132.139
[iplong] => 0
)
Array
(
[ip] => 69.204.125.71
[iplong] => 0
)
Array
(
[ip] => 76.77.139.72
[iplong] => 0
)
Array
(
[ip] => 50.82.236.23
[iplong] => 0
)
Array
(
[ip] => 68.197.139.155
[iplong] => 0
)
Array
(
[ip] => 188.29.165.19
[iplong] => 0
)
Array
(
[ip] => 92.14.251.192
[iplong] => 0
)
Array
(
[ip] => 122.151.11.144
[iplong] => 0
)
Array
(
[ip] => 2.122.114.91
[iplong] => 0
)
Array
(
[ip] => 31.100.182.110
[iplong] => 0
)
Array
(
[ip] => 199.7.157.11
[iplong] => 0
)
Array
(
[ip] => 46.44.179.76
[iplong] => 774681420
)
只有最后一个转换成功了,其他的都失败了,这是什么原因?
解决方案
http://blog.163.com/metlive@126/blog/static/1026327120104232330131/