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 Link to comment https://forums.phpfreaks.com/topic/159461-strip-subdomain-from-string/ Share on other sites More sharing options...
trq Posted May 24, 2009 Share Posted May 24, 2009 Take a look at substr and strpos. Link to comment https://forums.phpfreaks.com/topic/159461-strip-subdomain-from-string/#findComment-841147 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 />"; ?> Link to comment https://forums.phpfreaks.com/topic/159461-strip-subdomain-from-string/#findComment-841150 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 Link to comment https://forums.phpfreaks.com/topic/159461-strip-subdomain-from-string/#findComment-841280 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 Link to comment https://forums.phpfreaks.com/topic/159461-strip-subdomain-from-string/#findComment-841294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.