php中包含regular expression的字符串操作函数怎么用?
Getting the domain name out of a URL
<?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";
?>
This example will produce:
domain name is: php.net
////////////////////////////////
上面例子真有趣,还有很多regular expression的函数,一串/[^\.\/]+\.[^\.\/]+$/。。。。。。。。这样的东西怎么使用呢?
谢谢!