Be really carefull when using code wich assumes certain conditions!
Why this regular expersion will fail half of the time:
- It assumes the url starts with www. Wrong! eg: mail.google.com
- It assumes the url has 4 parts. Wrong! eg: www.google.com
- It assumes the 3rd part has 2 characters. Wrong: eg: www.google.com.au
- It assumes the 4th part has 2 characters. Wrong! eg: www.maps.google.com
Any of the other examples provided in this thread will work as a
charm, but the errors above are common in people who concetrate on
solving one example instead of thinking about the big picture.
On 26/01/2009, at 10:13 PM, renjith das wrote:
You can use the regular expression
Sorry a small mistake instead of 3 use 4 ie mathes[4]...
I think it may be helpful for you
$host= "www.networkstuff.co.nz";
preg_match('/^(w{3})\.([a-zA-Z]+)\.([a-zA-z]{2})\.([a-
zA-z]{2})/', $host, $matches);
$returnedString = $matches[4]
echo $returnedString;
Regards
Renjith
On Mon, Jan 26, 2009 at 10:08 PM, renjith das <[email protected]>
wrote:
You can use the regular expression
I think it may be helpful for you
$host= "www.networkstuff.co.nz";
preg_match('/^(w{3})\.([a-zA-Z]+)\.([a-zA-z]{2})\.([a-
zA-z]{2})/', $host, $matches);
$returnedString = $matches[3]
echo $returnedString;
Regards
Renjith
On Mon, Jan 26, 2009 at 9:20 PM, Michael <[email protected]>
wrote:
What I need to do is grab the TLD from a URL string-
eg: www.networkstuff.co.nz - what I want returned is the 'nz' part.
What is the best way to achieve this?
Thanks in anticipation.
Michael
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---