<?php
// 从 URL 中取得主机名
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
$host = $matches[2];$smart=current(explode(".",$host));
echo $smart;
?>
// 从 URL 中取得主机名
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
$host = $matches[2];$smart=current(explode(".",$host));
echo $smart;
?>
这句的意思就是匹配以“HTTP://”开头,只限出现一次,同时下一个不能为“/”。
“\”这个是转义的意思。
2、/^(?:http:\/\/)?(.+)\.[^\/]+/i