simonp Posted April 30, 2010 Share Posted April 30, 2010 Hi, I need to be able to split a domain name into two variables - the bit before the 'dot' and the bit after eg microsoft.com I need domain = microsoft tld = com (there will always be only one 'dot') What's the best way to do this? Thanks Simon Quote Link to comment Share on other sites More sharing options...
cags Posted April 30, 2010 Share Posted April 30, 2010 $input = 'microsoft.com'; $domain = strtok($input, '.'); $tld = strtok(''); Quote Link to comment Share on other sites More sharing options...
OOP Posted April 30, 2010 Share Posted April 30, 2010 $url = "microsoft.com"; $url_parts = explode('.',$url); print_r($url_parts); Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 30, 2010 Share Posted April 30, 2010 As you can see there are many ways to do what you wish. list($domain,$tld) = explode('.',$url); if the results of explode could be varying, as if you really dont know how many dots the url would have then an array is good as you can work through it figuring out what you have. If, as you state, the url is a known and constant then it is easier to explode and assign the parts to variables all in one step. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
simonp Posted April 30, 2010 Author Share Posted April 30, 2010 Thanks guys - I went with the strtok which worked great. Simon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.