Location: PHPKode > scripts > cParseurl > cparseurl/cParseurl.php
<?php
  /**
  * This tiny class was written, because parse_url, though practical, does not
  * return all information sometimes needed.
  * Sometimes a domain name without "www" is needed or the top level domain.
  * 
  * The members correspond with the Array indizes that parse_url() returns
  * with the following additions:
  * If an URL is given without a scheme ("http://"), "http://" is assumed and added
  * 
  * USAGE: $oUrl = new cParseurl("my.domain.com/mypath/myfile.htm")
  * or
  * $oUrl = new cParseurl("http://my.domain.com/mypath/myfile.htm")
  * 
  * @var domain: The domain name itself (meaning without eventual "www" or other c-level-names)
  * example: cParseurl("dict.leo.org"), member $domain would return: "leo.org"
  * 
  * @var tld: Top-level-domain
  * example: cParseurl("dict.leo.org"), member $tld would return: "org"
  * 
  * @var bdomain: The domain name without tld
  * example: cParseurl("dict.leo.org"), member $bdomain would return: "leo"
  * 
  * @var aHost: Array that contains all Parts of the domain name
  * example: cParseurl("dict.leo.org"), member $aHost would return: Array("dict","leo","org");
  * 
  * @author Konstantinos Dafalias <hide@address.com>
  * @version 1.0 date
  */
	class cParseurl
	  {
			var $scheme;
			var $host;
			var $port;
			var $user;
			var $pass;
			var $path;
			var $query;
			var $fragment;
			var $domain;
			var $tld;
			var $bdomain;
			var $aHost;
			
			function cParseurl($sUrl)
			  {
					if(!strpos($sUrl,"://")) $sUrl = "http://".$sUrl;
					$aDomain = parse_url($sUrl);
					foreach($aDomain as $sKey=>$sValue)
					  {
							$this->$sKey = $sValue;
					  }
					$this->aHost = explode(".",$aDomain["host"]);
					$iHostfrags = count($this->aHost);
					$this->tld = $this->aHost[$iHostfrags-1];
					$this->bdomain = $this->aHost[$iHostfrags-2];
					$this->domain = $this->bdomain.".".$this->tld;				
			  }
	  }
?>
Return current item: cParseurl