|
如何用php代码获取Url中的domain(域名)呢?本文给大家一个参考代码,有需要的朋友,可以看看哦。
例1,
<?php
/**
Url中取主机域名
http://bbs.it-home.org
*/
function getExt($url){
$arr = parse_url($url);
$file = $arr['host'];
$ext = substr($file,strpos($file,".")+1);
return $ext;
}
//调用示例
$url="http://www.baidu.com/path.php?arg=value#anchor";
$qa=getExt($url);
var_dump($qa);
?>登录后复制 例2,
<?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";
?>登录后复制 |
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号