织梦
<code>{<span>dede:</span>geturl runphp=<span>'yes'</span>} <span>$url</span> = <span>$_SERVER</span>[<span>'HTTP_HOST'</span>]; preg_match(<span>"#[\w-]+\.(com|net|org|gov|cc|biz|info|cn|co)(\.(cn|hk|uk))*#"</span>, <span>$url</span>, <span>$match</span>); <span>@me</span> = <span>$match</span>[<span>0</span>]; {<span>/dede:geturl}</span></code>
PHP
<code><span><span><?php </span><span>$url</span> = <span>$_SERVER</span>[<span>'HTTP_HOST'</span>]; preg_match(<span>"#[\w-]+\.(com|net|org|gov|cc|biz|info|cn|co)(\.(cn|hk|uk))*#"</span>, <span>$url</span>, <span>$match</span>); <span>echo</span><span>$match</span>[<span>0</span>]; <span>?></span></span></span></code>
以上就介绍了PHP和织梦正则preg_match获取顶级域名,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。