function strstr_after($haystack, $needle, $case_insensitive = false) { $strpos = ($case_insensitive) ? 'stripos' : 'strpos'; $pos = $strpos($haystack, $needle); if (is_int($pos)) { return substr($haystack, $pos + strlen($needle)); } // Most likely false or null return $pos; } $domain=strstr_after("$_SERVER['HTTP_HOST']","www.",TRUE); print $domain; PHP:
Thanks nico that's brilliant, didn't think of it that way, I just wrote $host = substr($domain, 4, 40); and it worked, but not as clean as your version which I'll use, Cheers, Nick
Note that the www. depends on the domain in the URL. If someone visits your site without the www., you'd remove the first characters from your actual domain name.
The code I used worked fine..but I'm using yours now. I wrapped it in a ereg www if else etc to figure out when to do what. Cheers, Nick
Usually, there is not more than one occurrence of "www.", so if you use the str_replace(), it'll remove the www., or it'll leave the string like it is, if there's no www.. So you don't need to overkill it with checking and verifying. You can just use str_replace() and it'll give you always the same result.