0

我只需要从给我的一些网站列表中获取域名。我必须只取商店名称,不包括 .com、www 和子域。同样,我只需要取一个店名并插入数据库

例如。清单是

shopping.indiatimes.com
shopping.indiatimes.com
shopping.indiatimes.com
www.infibeam.com
adexmart.com
deals.sulekha.com    
deals.sulekha.com
www.ebay.in
deals.ebay.in
shop.seventymm.com
www.homeshop18.com
www.buytheprice.com
www.snapdeal.com
www.aircel.com
www.tradus.com
www.infibeam.com
www.futurebazaar.com
www.tradus.com
www.shoppingmantra.com
camera.zoomin.com
www.homeshop18.com

所以在这里我只想要域名,如,indiatimes,ebay,tradus,zoomin..等。

4

4 回答 4

1
foreach($domains as $domain)
   echo implode('', array_slice(explode('.', $domain), -2, 1));
于 2012-08-23T05:29:06.193 回答
0

这可以通过执行字符串爆炸然后取倒数第二个数组元素来完成。

$array = explode(".", "www.snapdeal.com");

$count = count($array);
$value = $array[$count - 2]
于 2012-08-23T05:31:26.860 回答
0
$url_to_check = "http://www.shopping.indiatimes.com";
$url1 = preg_replace('#^https?://#', '', $url_to_check);
$domain = implode('', array_slice(explode('.', $url1), -2, 1));
echo $domain; //this will echo indiatimes
于 2012-08-23T05:32:48.727 回答
0
$domain = parse_url("www.domainnames.com");
    $host = $domain['host'];       
     $exp  = explode('.' , $host);        
                if(isset($exp[2])){        
                $domainname = ($exp[1]);
                }else {           
                    $domainname = ($exp[0]);
                }
                $a []= $domainname;  

      $uniquenames = (array_unique($a));    
      print_r($uniquenames);
于 2012-08-23T06:13:58.183 回答