function parseHost($httpurl) { $httpurl = strtolower( trim($httpurl) ); if(empty($httpurl)) return ; $regx1 = ‘/https?:\/\/(([^\/\?#]+\.)?([^\/\?#-\.]+\.)(com\.cn|org\.cn|net\.cn|com\.jp|co\.jp|com\.kr|com\.tw)(\:[0-9]+)?)/i‘; $regx2 = ‘/https?:\/\/(([^\/\?#]+\.)?([^\/\?#-\.]+\.)(cn|com|org|net|cc|biz|hk|jp|kr|name|me|tw|la)(\:[0-9]+)?)/i‘; $host = $tophost = ‘‘; if(preg_match($regx1,$httpurl,$matches)) { $host = $matches[1]; } elseif(preg_match($regx2, $httpurl, $matches)) { $host = $matches[1]; } if($matches) $tophost = $matches[2] == ‘www.‘ ? $host:$matches[3].$matches[4].$matches[5]; return array($host,$tophost); }
时间: 2024-10-29 10:27:16