Ec (2); $ ip & quot; 2001: 0db8: 85a3: 08d3: 1319: 8a2e: 0370: 7334 & quot; & nbsp; 02 $ ip & quot; 2001: 0db8: 85a3: 08d3: 7334 & quot; & nbsp; 03if (filter_var ($ ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 )! False) & nbsp; script ec (2); script
$ Ip = "2001: 0db8: 85a3: 08d3: 1319: 8a2e: 0370: 7334 ";
02 // $ ip = "2001: 0db8: 85a3: 08d3: 7334 ";
03 if (filter_var ($ ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 )! = False)
04
05 {
06 echo $ ip. "is an IPv6 Address ";
07} else
08 {
09 echo $ ip. "is NOT an IPv6 Address ";
10}
11 //PHP5.2.0.x passed the test
The filter_var () function filters variables using the specified filter.
If the operation succeeds, filtered data is returned. If the operation fails, false is returned.
02 // literally from the ABNF in rfc3986 (thanks to 'wcp ')
03 function validateIPv6 ($ IP)
04 {
05 return preg_match ('/
06 (? :
07 (? :
08 (? : [A-f0-9] {} :) {6}
09 |
10 ::(? : [A-f0-9] {} :) {5}
11 |
12 (? : [A-f0-9 })? ::(? : [A-f0-9] {} :) {4}
13 |
14 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? ::(? : [A-f0-9] {} :) {3}
15 |
16 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? ::(? : [A-f0-9] {} :) {2}
17 |
18 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? : [A-f0-9 }:
19 |
20 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? ::
21)
22 (? :
23 [a-f0-9] {}: [a-f0-9}
24 |
25 (? :(? : [0-9] | [1-9] [0-9] | 1 [0-9] [0-9] | 2 [0-4] [0-9] | 25 [0-5]).) {3}
26 (? : [0-9] | [1-9] [0-9] | 1 [0-9] [0-9] | 2 [0-4] [0-9] | 25 [0-5])
27)
28 |
29 (? :
30 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? : [A-f0-9}
31 |
32 (? :(? : [A-f0-9] {} :) {} [a-f0-9 })? ::
33)
34) Z/ix ',
35 $ IP
36 );
37}
38?>