<?php
// 從 URL 中取得主機名
preg_match("/^(http:\/\/)?([^\/]+)/i",
" http://www.php.net/index.html", $matches);
$host = $matches[2];
// 從主機名中取得後面兩段
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
方法還有很多,只是覺得這兩種應該是最直接的。