Validate the value as an IP address in PHP

Description

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

Example


<?php//  w  ww  .  j  ava 2 s.  c  o  m
    $ip = "192.168.0.1";

    if(!filter_var($ip, FILTER_VALIDATE_IP)){
        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