php.net 上有一个示例如何分两步获取最后两个域段:
<?php
//get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
$host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";
/* Output is php.net */
?>
但是我怎样才能一步完成,只使用一个 preg_match 表达式呢?