xref: /php-src/ext/filter/tests/018.phpt (revision 74859783)
1--TEST--
2filter_var() and FILTER_VALIDATE_IP
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7var_dump(filter_var("192.168.0.1", FILTER_VALIDATE_IP));
8var_dump(filter_var("192.168.0.1.1", FILTER_VALIDATE_IP));
9var_dump(filter_var("::1", FILTER_VALIDATE_IP));
10var_dump(filter_var("fe00::0", FILTER_VALIDATE_IP));
11var_dump(filter_var("::123456", FILTER_VALIDATE_IP));
12var_dump(filter_var("::1::b", FILTER_VALIDATE_IP));
13var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP));
14var_dump(filter_var("192.168.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE));
15var_dump(filter_var("192.0.34.166", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE));
16var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
17var_dump(filter_var("192.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
18var_dump(filter_var("100.64.0.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
19var_dump(filter_var("100.127.255.255", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
20var_dump(filter_var("192.0.34.166", FILTER_VALIDATE_IP));
21var_dump(filter_var("256.1237.123.1", FILTER_VALIDATE_IP));
22var_dump(filter_var("255.255.255.255", FILTER_VALIDATE_IP));
23var_dump(filter_var("255.255.255.255", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
24var_dump(filter_var("", FILTER_VALIDATE_IP));
25var_dump(filter_var(-1, FILTER_VALIDATE_IP));
26var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
27var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
28var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
29var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE));
30var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
31echo "Done\n";
32?>
33--EXPECT--
34string(11) "192.168.0.1"
35bool(false)
36string(3) "::1"
37string(7) "fe00::0"
38bool(false)
39bool(false)
40string(9) "127.0.0.1"
41bool(false)
42string(12) "192.0.34.166"
43bool(false)
44string(9) "192.0.0.1"
45string(10) "100.64.0.0"
46string(15) "100.127.255.255"
47string(12) "192.0.34.166"
48bool(false)
49string(15) "255.255.255.255"
50bool(false)
51bool(false)
52bool(false)
53bool(false)
54bool(false)
55string(3) "::1"
56bool(false)
57string(9) "127.0.0.1"
58Done
59