PHP code Ip2long Loop problem

Source: Internet
Author: User
Print_r ($dataIp);            foreach ($dataIp as $key = + $value) {                $data [' IP ']     =   $value;                $data [' iplong ']     =   Bindec (Decbin (Ip2long ($value)));                                            Print_r ($data);                         }


The results are printed as follows:

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
)


Only the last one succeeds, the others fail, what is the reason?


Reply to discussion (solution)

Ip2long can't convert an array?

No problem

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)

But I don't know what you're doing.

Moderator adults have not changed the code, I have tried in the local countless times have only read the last one. I don't know what the reason is.

 
  $value) {$data [' IP ']     =   $value; $data [' iplong ']     =   Bindec (Decbin (Ip2long ($value)));                            Print_r ($data);             }

Output
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)

is normal.

If you put Print_r ($data); Put it outside the loop, it's the last one.

???, normal.

My full code is like this.

$dataIp = explode ("\ n", $_post[' IP '), if (Empty ($dataIp)) {$this->error (' not filled ip! ');} $dataIp = Array (' 208.104.70.215 ', ' 74.101.176.171 ', ' 73.17.35.30 ', ' 70.198.197.3 ', ' 46.44.179.76 ');p Rint_r ($dataIp ), foreach ($dataIp as $key = + $value) {        $data [' IP ']     =   $value;        $data [' iplong ']     =   Bindec (Decbin (Ip2long ($value)));                                    Print_r ($data);             }

If the IP in the fifth row of numbers is entered after the form is submitted, the printed array is the same regardless of whether the fifth line is commented.
But the results of the cycle are different, the results are shown. I really don't know how this problem came up, tangled up a good while.

Thank you for the upstairs several to find the problem, is the form inside the front and rear space resulting in not getting the value.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.