Return to Snippet

Revision: 12003
at February 26, 2009 19:13 by xtheonex


Initial Code
function striptodomain($url) {
	if ((substr_count($url, 'http://www.')) > 0) {
		$url = str_replace('http://www.', '', $url);
	} elseif ((substr_count($url, 'http://')) > 0) {
		$url = str_replace('http://', '', $url);
	} elseif ((substr_count($url, 'www.')) > 0) {
		$url = str_replace('www.', '', $url);
	}
	if ((substr_count($url, '/')) > 0) {
		$url = substr($url, 0, strrpos($url, '/'));
	}
	return $url;
}

Initial URL

                                

Initial Description
This is a function i created to basically stip a url down to its domain name and nothing else.<br>
For eg.<br>
If you passed it any of the following urls it would return the same value.
<br>http://www.google.com/
<br>www.google.com
<br>http://www.google.com/search?hl=en&q=jadeyo&btnG=Google+Search&meta=
<br>All of the above urls would return the same varibale of 'google.com'

Initial Title
Strip URL to its domain name...

Initial Tags

                                

Initial Language
PHP