Location: PHPKode > scripts > class.uri > class-uri/class.uri.php
<?

/*

	class.uri.php -- hide@address.com

	usage:

	$x = new uri("http://localhost/test/huh.php?var1=001&var2=002");

	$x->getVariable("var1"); (returns "001")
	$x->setVariable("var3", "003");
	$x->unsetVariable("var2");

	$x->getUri(); (returns "http://localhost/test/huh.php?var1=001&var3=003")

	more to come...

*/


	class uri {

		var $uri;
		var $base;
		var $para;

		function uri($def="") {

			$this->uri = $def;
			preg_match('/^(.*\?)(.*)$/', $this->uri, $matches);

			$this->base = $matches[1];
			$this->paraFromString($matches[2]);

		}

		function paraFromString($string) {

			unset($this->para);
			
			$tab = (explode("&", $string));

			foreach($tab as $v) {
				
				$temp = explode("=", $v);
				$this->para["$temp[0]"] = $temp[1];

			}

		}

		function setVariable($var, $val) {

			$this->para["$var"] = $val;

		}

		function setBase($val) {

			$this->base = $val;

		}

		function unsetVariable($var) {

			unset($this->para["$var"]);

		}

		function getVariable($var) {

			return $this->para["$var"];

		}

		function getUri() {

			foreach($this->para as $k=>$v) {

				$temp[] .= $k."=".htmlentities(urlencode($v));

			}

			return $this->base.implode("&", $temp);

		}

		function get() {

			return $this->getUri();

		}

	}

?>
Return current item: class.uri