PHP FILTER_VALIDATE_IP Filter
Complete PHP Filter Reference
Definition and Usage
The FILTER_VALIDATE_IP filter validates value as an URL.
- Name: "validate_ip"
- ID-number: 275
Possible flags:
- FILTER_FLAG_IPV4 - Requires the value to be a valid IPv4 IP (like
255.255.255.255)
- FILTER_FLAG_IPV6 - Requires the value to be a valid IPv6 IP (like
2001:0db8:85a3:08d3:1319:8a2e:0370:7334)
- FILTER_FLAG_NO_PRIV_RANGE - Requires the value to be a RFC specified
private range IP (like 192.168.0.1)
- FILTER_FLAG_NO_RES_RANGE - Requires that the value is not within the
reserved IP range. This flag takes both IPV4 and IPV6 values
Example 1
<?php
$ip = "192.168.0.1";
if(!filter_var($ip, FILTER_VALIDATE_IP))
{
echo "IP is not valid";
}
else
{
echo "IP is valid";
}
?>
|
The output of the code will be:
Example 2
<?php
$ip = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
echo "IP is not valid";
}
else
{
echo "IP is valid";
}
?>
|
The output of the code will be:
Complete PHP Filter Reference

Whether you're new to XML or already an advanced user, the user-friendly views and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to meet your XML and Web development needs from start to finish.
New features in Version 2010!
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- XBRL validator, taxonomy editor, taxonomy wizard
- Support for Office Open XML (OOXML)
- Graphical WSDL 1.1/2.0 editor & SOAP debugger
- JSON editing & conversion
- Java, C#, C++ code generation
- 32-bit and 64-bit versions
- And much more!
Download a free trial today!
|
|
|
|