xref: /PHP-8.1/ext/standard/tests/network/ip.phpt (revision 0c6d06ec)
1--TEST--
2ip2long() & long2ip() tests
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9
10$array = array(
11    "127.0.0.1",
12    "10.0.0.1",
13    "255.255.255.255",
14    "255.255.255.0",
15    "0.0.0.0",
16    "66.163.161.116",
17);
18
19foreach ($array as $ip) {
20    var_dump($long = ip2long($ip));
21    var_dump(long2ip($long));
22}
23
24var_dump(ip2long(""));
25var_dump(ip2long("777.777.777.777"));
26var_dump(ip2long("111.111.111.111"));
27
28var_dump(long2ip(-110000));
29
30echo "Done\n";
31?>
32--EXPECT--
33int(2130706433)
34string(9) "127.0.0.1"
35int(167772161)
36string(8) "10.0.0.1"
37int(-1)
38string(15) "255.255.255.255"
39int(-256)
40string(13) "255.255.255.0"
41int(0)
42string(7) "0.0.0.0"
43int(1118019956)
44string(14) "66.163.161.116"
45bool(false)
46bool(false)
47int(1869573999)
48string(13) "255.254.82.80"
49Done
50