1. 程式人生 > >PHP和織夢正則preg_match獲取頂級域名

PHP和織夢正則preg_match獲取頂級域名

織夢

{dede:geturl runphp='yes'}  
$url = $_SERVER['HTTP_HOST'];
preg_match("#[\w-]+\.(com|net|org|gov|cc|biz|info|cn|co)(\.(cn|hk|uk))*#", $url, $match);
@me =  $match[0];
{/dede:geturl}

PHP

<?php
$url = $_SERVER['HTTP_HOST'];
preg_match("#[\w-]+\.(com|net|org|gov|cc|biz|info|cn|co)(\.(cn|hk|uk))*#"
, $url, $match); echo $match[0]; ?>