<?php
/* v.0.1 latest:2013/2/25 designed by 不惑仔
*/
class iri{
public static function absoluteHere($scheme='http'){
	return $scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
}
public static function useAbsolute($url,$scheme='http',$relative=true){
	if($relative){
		$url=dirname($_SERVER['PHP_SELF'])."/$url";
	}
	$s=parse_url($url);
	if(empty($s['scheme'])) $s['scheme']=$scheme;
	if(empty($s['host'])) $s['host']=$_SERVER['HTTP_HOST'];
	#$p=sprintf('%s://%s%s',$s['scheme'],$s['host'],$s['path']);
	$p="$s[scheme]://$s[host]$s[path]";
	if(empty($s['query'])&&empty($s['fragment'])){
	 return $p;
	}
	if(!empty($s['query'])&&empty($s['fragment'])){
		return "$p?$s[query]";
	}
	if(empty($s['query'])&&!empty($s['fragment'])){
		return "$p#$s[fragment]";
	}
	if(!empty($s['query'])&&!empty($s['fragment'])){
		return "$p?$s[query]#$s[fragment]";
	}
}
}
?>