Ec (2); php regular html URL code $ pattern & quot; [w-] +. (com | net | org | gov | cc | biz | info | cn )(. (cn | hk) * & quot; & nbsp; preg_match ($ pattern, $ url, $ matches); & nbsp; & nbsp; if (count ($ matches) & gt script ec (2); script
Php regular html URL code
$ Pattern = "/[w-] +. (com | net | org | gov | cc | biz | info | cn) (. (cn | hk ))*/";
Preg_match ($ pattern, $ url, $ matches );
If (count ($ matches)> 0 ){
Return $ matches [0];
} Else {
$ Rs = parse_url ($ url );
$ Main_url = $ rs ["host"];
If (! Strcmp (long2ip (sprintf ("% u", ip2long ($ main_url), $ main_url )){
Return $ main_url;
} Else {
$ Arr = explode (".", $ main_url );
$ Count = count ($ arr );
$ EndArr = array ("com", "net", "org", "3322"); // com.cn net.cn
If (in_array ($ arr [$ count-2], $ endArr )){
$ Domain = $ arr [$ count-3]. ".". $ arr [$ count-2]. ".". $ arr [$ count-1];
} Else {
$ Domain = $ arr [$ count-2]. ".". $ arr [$ count-1];
}
Return $ domain;
} // End if (! Strcmp ...)
} // End if (count ...)
} // End function