SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Dec 5, 2003, 01:11 #1
- Join Date
- Oct 1999
- Location
- Vancouver, BC, Canada
- Posts
- 983
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code to extract ONLY the domain.com part of an address?
I am trying to find some code that will "extract" only the domain.com portion of some text input.
For example of possible input:
www.domain.com
http://domain.com
http://www.domain.com
Basically, I need only the "www." and "http://" part striped away.. if it exists.
Thanks!
-
Dec 5, 2003, 03:12 #2
- Join Date
- Oct 2001
- Location
- Estonia
- Posts
- 141
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
preg_replace('/((^http:\/\/www\.)|(^http:\/\/)|(^www\.))/', '', $input);
you can't use just (www\.) as it will cut out all 'www.' from string: www.thiswww.com -> this.com(2B) or (not 2B) = FF
-
Dec 5, 2003, 07:31 #3
i'm not a regex expert so i dont know the exact regex to use but in Hulkur example it would be better so that you cover all possible cases to not use http: or www in the regex but to do (in english not regex) search from beginning of string for any characters EXCEPT a period until you get to the first period then stop so you would cover http://blah.domain.com as well. Sorry that i dont have the regex for ya. Maybe a guru will be able to post it for us?
Erh
-
Dec 5, 2003, 07:33 #4
maybe this '^[^.]*\.' not sure if the * is in the right place.
Erh
-
Dec 5, 2003, 07:35 #5
- Join Date
- Oct 2003
- Location
- Germany
- Posts
- 2,195
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You might want to have a look at parse_url.
-
Dec 8, 2003, 03:11 #6
- Join Date
- Oct 2001
- Location
- Estonia
- Posts
- 141
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if you want domain starting from first dot then:
preg_replace('/([^\.]+\.)/', '', $input);(2B) or (not 2B) = FF
Bookmarks