<?php
/**
* is_ipaddr() Function
* Created by: Joshua H. (TRUSTAbyss)
*
* This function returns a boolean value.
* Usage: is_ipaddr("IP");
*/
function is_ipaddr($ip)
{
$result = FALSE;
// Check to see if the IP Address is valid.
if (preg_match("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/",
$ip,
$matches)) {
// Check each of the IP digits to see if they're less than or equal to 255 (valid IP Range).
if (($matches[1] <= 255) && ($matches[2] <= 255) && ($matches[3] <= 255) && ($matches[4] <= 255))
{
$result = TRUE; // Valid IP.
}
}
return $result;
}
// Example code below.
if (is_ipaddr("65.5.240.229"))
{
echo "This is a valid IP Address. ";
}
else
{
echo "This is NOT a valid IP Address.";
}
?>