![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FILTER_VALIDATE_IP constant in PHP
The FILTER_VALIDATE_IP constant validates an IP address.
Flags
FILTER_FLAG_IPV4 − The value must be a valid IPv4 address
FILTER_FLAG_IPV6 − The value must be a valid IPv6 address
FILTER_FLAG_NO_PRIV_RANGE − The value must not be within a private range
FILTER_FLAG_NO_RES_RANGE − The value must not be within a reserved range
Return
The FILTER_VALIDATE_IP constant does not return anything.
Example
<?php $ip = "35.2.1"; if (filter_var($ip, FILTER_VALIDATE_IP)) { echo("Valid IP address!"); } else { echo("Invalid IP address!"); } ?>
The following is the output.
Invalid IP address!
Let us see another example.
<?php $ip = "127.0.0.1"; if (filter_var($ip, FILTER_VALIDATE_IP)) { echo("Valid IP address!"); } else { echo("Invalid IP address!"); } ?>
Here is the output.
Valid IP address!
Advertisements