dreamwest Posted May 24, 2009 Share Posted May 24, 2009 How can i strip a ".com" and the sudomain "sub." from a url Ive already striped the http:// part now im just left with the rest "sub.site.com" $url = parse_url("http://sub.site.com"); $display_website = $url['host'] ); What i need is just the "site" part of the url Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2009 Share Posted May 24, 2009 Take a look at substr and strpos. Quote Link to comment Share on other sites More sharing options...
papaface Posted May 24, 2009 Share Posted May 24, 2009 <?php $url = parse_url("http://sub.site.com"); $explode = explode(".", $url['host']); echo "Sub = " . $explode[0] . "<br />"; echo "Site = " . $explode[1] . "<br />"; echo "TLD = " . $explode[2] . "<br />"; ?> Quote Link to comment Share on other sites More sharing options...
dreamwest Posted May 24, 2009 Author Share Posted May 24, 2009 <?php $url = parse_url("http://sub.site.com"); $explode = explode(".", $url['host']); echo "Sub = " . $explode[0] . "<br />"; echo "Site = " . $explode[1] . "<br />"; echo "TLD = " . $explode[2] . "<br />"; ?> Thanks. this is alot simpler, i did it with strpos() but its a bit of work $url = parse_url($url); $url = $url['host']; $url = substr($url, 0, -4); //remove .com $url_subdomain = strpos($url, '.'); // if subdomain count characters if ($url_subdomain !== false) { $url_subdomain = $url_subdomain +1; $url = substr($url, $url_subdomain); // remove subdomain } Think ill use explode instead Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted May 24, 2009 Share Posted May 24, 2009 i just wrote a big class that dealt a lot with explode... such an awesome function! haha 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.