php专区

 首页 > php专区 > PHP应用 > php函数大全 > php 从字符串中获取URL中获得域名 - php函数

php 从字符串中获取URL中获得域名 - php函数

分享到:
【字体:
导读:
          本教程主要主讲从字符串中得出url的域名部份,下面来看看吧。希望对我有帮助。例如:http: www phpfensi com 得到 www phpfensi com...

php 从字符串中获取URL中获得域名

本教程主要主讲从字符串中得出url的域名部份,下面来看看吧。希望对我有帮助。

例如:http://www.phpfensi.com  得到  www.phpfensi.com

  1. function get_domain($url){ 
  2. $pattern = "/[w-] .(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/"
  3. preg_match($pattern$url$matches); 
  4. if(count($matches) > 0) { 
  5. return $matches[0]; 
  6. }else
  7. $rs = parse_url($url); 
  8. $main_url = $rs["host"]; 
  9. if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) { 
  10. return $main_url
  11. }else
  12. $arr = explode(".",$main_url); 
  13. $count=count($arr); 
  14. $endArr = array("com","net","org","3322");//com.cn net.cn 等情况 
  15. if (in_array($arr[$count-2],$endArr)){ 
  16. $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1]; 
  17. }else
  18. $domain = $arr[$count-2].".".$arr[$count-1]; 
  19. return $domain
  20. }// end if(!strcmp...) 
  21. }// end if(count...) 
  22. }// end function 
分享到:
什么函数能够把文件从一个目录下转移到另...
什么函数能够把文件从一个目录下转移到另外一个目录下? 问:什么函数能够把文件从一个目录下转移到另外一个目录下? 答:PHP中没有直接转移的函数。不过你可以试着这样来做。  
如何用php创建与删除多级目录函数 - php...
如何用php创建与删除多级目录函数   function deldir($dir)   {      $dh=opendir($dir);      while ($file=readdir($dh))      {     if($file!="." && $file!="..")     {   $fullpath=$dir."/".$file;   if(!is_dir($fullpath))   {...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……