Validate ip address php

<?php
$ip = “173.0.52.150”;
if(preg_match(“/^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/”,$ip)) {
$parts=explode(“.”,$ip);
foreach($parts as $value){
if(intval($value)>255 || intval($value)<0)
echo “Invalid”;
}
echo “Valid IP address”;
}
?>