Validate the value as an IPv6 address in PHP

Description

The following code shows how to validate the value as an IPv6 address.

Example


<?php/*  w  w  w .j  a  v a2  s  .  c  o  m*/
    $ip = "2002:0db9:85a3:07d3:1219:8a2e:0470:7634";

    if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
        echo "IP is not valid";
    }else{
        echo "IP is valid";
    }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone