xref: /PHP-5.3/ext/filter/tests/018.phpt (revision fbe4532b)
1--TEST--
2filter_var() and FILTER_VALIDATE_IP
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
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("192.0.34.166", FILTER_VALIDATE_IP));
19var_dump(filter_var("256.1237.123.1", FILTER_VALIDATE_IP));
20var_dump(filter_var("255.255.255.255", FILTER_VALIDATE_IP));
21var_dump(filter_var("255.255.255.255", FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
22var_dump(filter_var("", FILTER_VALIDATE_IP));
23var_dump(filter_var(-1, FILTER_VALIDATE_IP));
24var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
25var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
26var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
27var_dump(filter_var("::1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE));
28var_dump(filter_var("127.0.0.1", FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
29echo "Done\n";
30?>
31--EXPECT--
32string(11) "192.168.0.1"
33bool(false)
34string(3) "::1"
35string(7) "fe00::0"
36bool(false)
37bool(false)
38string(9) "127.0.0.1"
39bool(false)
40string(12) "192.0.34.166"
41bool(false)
42string(9) "192.0.0.1"
43string(12) "192.0.34.166"
44bool(false)
45string(15) "255.255.255.255"
46bool(false)
47bool(false)
48bool(false)
49bool(false)
50bool(false)
51string(3) "::1"
52bool(false)
53string(9) "127.0.0.1"
54Done
55