1

Possible Duplicate:
Parsing Domain From URL In PHP

Basically I have a form where a user puts in a url of a page to save (e.g. http://domain.com/random/page) and I want it to just get the domain name of the website (domain.com). How do I do this?

Community
  • 1
  • 1
ritch
  • 1,760
  • 14
  • 37
  • 65

2 Answers2

3

Look the function parse_url(), and get the "host" key from the array.

fvox
  • 1,077
  • 6
  • 8
2

I would remove the http:// and then split the string by /. Take the first value of the resulting array from the split.

zsalzbank
  • 9,685
  • 1
  • 26
  • 39