The example in this article describes how PHP uses the preg_match() function to verify the IP address. Share it with everyone for your reference, the details are as follows:
<?php /* *@return Boolen *@param String $ip 要匹配的ip地址 *@param String $pat 匹配的正则规则 *@param Boolen 匹配成功后返回的布尔值 *preg_match() *0为不成功,1为成功 */ function fun($ip){ //0.0.0.0--- 255.255.255.255 $pat = "/^(((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))$/"; if(preg_match($pat,$ip)){ $num = preg_match($pat,$ip); return $num; }else{ $num = preg_match($pat,$ip); return $num; } } echo fun("255.255.255.255");
I hope this article will be helpful to everyone in PHP programming.
For more articles related to how PHP uses the preg_match() function to verify the IP address, please pay attention to the PHP Chinese website!