php获取URL中的host
PHP 2016/5/30 16:01:06 点击:不统计
转载%77%77%77请%2E%66%6F%72%61%73%70%2E%63%6E注明
需要说明一点 parerror_reportse_url 会有Notice 的提示,如果想去掉,则要修改error_report 的错误级别。
参考函数
function get_host($url = ""){
if('' == $url)return '';
$url = trim($url);
if(function_exists(parse_url)){
$result = @parse_url($url);
return $result['host'];
}else{
$search = '~^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?~i';
preg_match_all($search, $url ,$result);
return $result[4][0];
}
}
原载于:文章来源:www.forasp.cn网站制作学习
·上一篇:php正则自动添加nofollow >> ·下一篇:php常见时间处理 前一天 后一天 >>