Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i need a php function to extract domain with tld from a url or domain with tld and subdomain if there is.

example:

http://minova.tumblr.com/post/145515 >> minova.tumblr.com

http://www.tumblr.com/about/1 >> tumblr.com

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
271 views
Welcome To Ask or Share your Answers For Others

1 Answer

http://php.net/manual/en/function.parse-url.php - special focus on 'host' and 'path'.

Example:

$var = "http://minova.tumblr.com/post/145515";
print_r(parse_url($var));

Outputs:

array (
  'scheme' => 'http',
  'host'   => 'minova.tumblr.com',
  'path'   => '/post/145515',
)

Example II:

$var = "http://minova.tumblr.com/post/145515";
print parse_url($var, PHP_URL_HOST);

Outputs:

minova.tumblr.com

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...