How To Check IP Is A Valid Public IP Address

How can I check a IP address is a valid public IP address in PHP ? a clean IP

You can use native PHP function filter_var with FILTER_VALIDATE_IP to check the IP address is a valid public IP address or not

$ip = "192.0.0.1";

if (filter_var($ip, FILTER_VALIDATE_IP)) {
    // a valid public IP address
} else {
    // a invalid public IP address
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments