php检测域名格式是否正确
1.检测域名格式正确性的函数//检测域名格式
function CheckUrl($C_url){
$str="/^http(s?):\/\/(?:+\.)+{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/";
if (!preg_match($str,$C_url)){
return false;
}else{
return true;
}
}
2.使用方法
$url = "http://www.baidu.com/"; //填写你要检测的域名
if(!CheckUrl($url)){
echo "域名格式不正确";
}else{
echo "域名格式正确";
}
页:
[1]