从URL解析域 [英] Parsing domain from a URL
本文介绍了从URL解析域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要构建一个从URL解析域的函数.
I need to build a function which parses the domain from a URL.
所以,用
http://google.com/dhasjkdas/sadsdds/sdda/sdads.html
或
http://www.google.com/dhasjkdas/sadsdds/sdda/sdads.html
它应该返回google.com
与
http://google.co.uk/dhasjkdas/sadsdds/sdda/sdads.html
它应该返回google.co.uk
.
推荐答案
查看 parse_url()
:>
$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
echo $parse['host']; // prints 'google.com'
parse_url
不能很好地处理错误整齐的网址,但是如果您通常希望有不错的网址,那就很好了.
parse_url
doesn't handle really badly mangled urls very well, but is fine if you generally expect decent urls.
这篇关于从URL解析域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文