Simple verification of IPv6 PHP code-PHP source code

Source: Internet
Author: User
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?>

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.