function rel2abs($rel, $base)
{
$rel = str_replace('\\', '/', $rel); //替换‘\’为'/'
$base = str_replace('\\', '/', $base);
if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; //绝对地址
if ($rel[0]=='#') return $base.$rel; //#
if($rel[0]=='?') return preg_replace('#\?[^/]*$#', '', $base).$rel; //?
extract(parse_url($base)); //解析URL并将组成部分导入到当前的符号表
$path = preg_replace('#/[^/]*$#', '', $path); //去除非路径部分
if ($rel[0] == '/') $path = ''; //绝对路径
if(isset($port)) $host .= ":$port"; //带端口
$abs = "$host$path/$rel"; //路径
$re = array('#(/\.?/)#', '#/[\w-.]+/\.\./#'); //将 '//' 或'/./'或 '/foo/../' 替换为 '/'
for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
return $scheme.'://'.$abs; //最终地址
}