How to validate a variable is IP address in Php?
In this post, This function checks whether a variable is IP address or not. IP address validation in PHP
1. Code:
<?php function checkIsIp($var){ return false !== filter_var($var, FILTER_VALIDATE_IP); } var_dump(checkIsIp("132.16.13.28")); echo "<br>"; var_dump(checkIsIp("12345")); ?>
2. Example:
Input:
INput: "132.16.13.28" Input: "12345"
Output:
Output: true Output: false