当前位置:Gxlcms > PHP教程 > PHP代码ip2long循环有关问题

PHP代码ip2long循环有关问题

时间:2021-07-01 10:21:17 帮助过:19人阅读

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] => 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
(
[ip] => 208.104.70.215
[iplong] => 3496494807
)
Array
(
[ip] => 74.101.176.171
[iplong] => 1248178347
)
Array
(
[ip] => 73.17.35.30
[iplong] => 1225859870
)
Array
(
[ip] => 70.198.197.3
[iplong] => 1187431683
)
Array
(
[ip] => 46.44.179.76
[iplong] => 774681420
)


但不知你想干什么
------解决思路----------------------

$dataIp = array('208.104.70.215', '74.101.176.171', '73.17.35.30', '70.198.197.3', '46.44.179.76');

foreach ($dataIp as $key=>$value) {
$data['ip'] = $value;
$data['iplong'] = bindec(decbin(ip2long($value)));
print_r($data);
}

输出

Array
(
[ip] => 208.104.70.215
[iplong] => 3496494807
)
Array
(
[ip] => 74.101.176.171
[iplong] => 1248178347
)
Array
(
[ip] => 73.17.35.30
[iplong] => 1225859870
)
Array
(
[ip] => 70.198.197.3
[iplong] => 1187431683
)
Array
(
[ip] => 46.44.179.76
[iplong] => 774681420
)

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

人气教程排行