PHP HTTP_HOST subdomain extraction given that a subdomain be a wildcard and contain more than one?

First of all I would explode(and use the first index in the array) on a slash just to be sure that the string ends with the TLD Then I would cut it with a preg_replace. This rexexp matches the domain+tld regardless of tld type. Beware however this would give a problem with 2&3 letter domains.

But it should give a push to the right direction a-zA-Z0-9+\.((a-zA-Z{2,6})|(a-zA-Z{2,3}\. A-zA-Z{2,3}))$ Edit: as pointed out: . Museum is also possible, so edited the first pattern in the TLD part And of course TLD's like .

UK could behave differently then co. Uk ugh.. it's not that easy.

First of all I would explode(and use the first index in the array) on a slash just to be sure that the string ends with the TLD. Then I would cut it with a preg_replace. This rexexp matches the domain+tld regardless of tld type.

Beware however this would give a problem with 2&3 letter domains. But it should give a push to the right direction.... a-zA-Z0-9+\.((a-zA-Z{2,6})|(a-zA-Z{2,3}\. A-zA-Z{2,3}))$ Edit: as pointed out: .

Museum is also possible, so edited the first pattern in the TLD part.... And of course TLD's like . UK could behave differently then co. Uk ugh.. it's not that easy...

Ouch. You don't think . Info, .

Museum etc have a right to exist? :) – bzlm Aug 5 '10 at 13:19 ouch, you are totally right. – Deefjuh Aug 5 '10 at 13:20.

With preg_match, you can extract the subdomain and tld parts in one go, like this: function get_domain_parts($domain) { $parts = array(); $pattern = "/(.*)\. Buggedcom\.(.*)/"; if (preg_match($pattern, $domain, $parts) == 1) { return array($parts1, $parts2); } else { return FALSE; } } $result = get_domain_parts("multi.sub.test.buggedcom.co. Uk"); if ($result) { echo($result0 ." and " .

$result1); // multi.sub. Test and co.Uk }.

Because this won't be run on a definitive domain so I can't check against anything. Also it's run before configuration loads in the base url for various optimization/caching reasons. – buggedcom Aug 5 '10 at 13:20 oic, I guess you'll have go go with evolve's solution then :) – André Laszlo Aug 5 '10 at 13:25.

Not to be nit-picky, but technically speaking .co. Uk is a second level domain. .

Uk is the "Country Code Top Level Domain" in that case, and the . Co is for "Commercial Use" defined by the United Kingdom. This might not answer your question though.

Wikipedia has a pretty complete list of TLD's, as you can see they only contain 1 "dot" followed by 1 "string".

I think it answers the question. Just not in the way the OP had hoped. :) – bzlm Aug 5 '10 at 13:21 Oh yeah.

I did know that, sorry incorrect example. – buggedcom Aug 5 '10 at 13:49.

I think the solution to this is better handled by those trying to do the same thing... there's a bunch of better URL parsing functions in the comments to PHP docs for parse_url function that might work better: php.net/manual/en/function.parse-url.php.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions