假设当前html页面url为http://www.abc.com/bbs/showtopic.php?tid=1
在该页面中的a标签的href属性有很多种可能,例如:
1. href=/bbs/thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/bbs/thread-2-1.html
2. href=/thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/thread-2-1.html
3. href=./thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/bbs/thread-2-1.html
4. href=../thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/thread-2-1.html
5. href=list.php?page=1 那么该链接的绝对url应该为http://www.abc.com/bbs/list.php?page=1等等很多情况
在java中可以通过URL(URL context, String spec)这个构造函数来得到
请问php中该怎么实现,是不是只能自己写个类似Java中的实现方式
谢谢赐教!!!
在该页面中的a标签的href属性有很多种可能,例如:
1. href=/bbs/thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/bbs/thread-2-1.html
2. href=/thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/thread-2-1.html
3. href=./thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/bbs/thread-2-1.html
4. href=../thread-2-1.html 那么该链接的绝对url应该为http://www.abc.com/thread-2-1.html
5. href=list.php?page=1 那么该链接的绝对url应该为http://www.abc.com/bbs/list.php?page=1等等很多情况
在java中可以通过URL(URL context, String spec)这个构造函数来得到
请问php中该怎么实现,是不是只能自己写个类似Java中的实现方式
谢谢赐教!!!
就说最简单用php实现的为静态
首先
www.abc.com/index.php/b/c.html
相当于www.abc.com/index.php?id=b&mingcheng=c
然后在index页面用$_SERVER[PATH_INFO]
变量来输出看应该就是/b/c.htmlfunction expl($str)
{
$str=explode('.',$str);
$str=explode('/',$str);
return $str;
}
$str=expl($_SERVER[PATH_INFO]);
$id=$str[1];//这个时候id的值就是b
$mingcheng=$str[2];//这个时候mingcheng的值就是c了
{
$str=explode('.',$str);
$str=explode('/',$str[0]);
return $str;
}
$str=expl($_SERVER[PATH_INFO]);
$id=$str[1];//这个时候id的值就是b
$mingcheng=$str[2];//这个时候mingcheng的值就是c了
realpath() 扩展所有的符号连接并且处理输入的 path 中的 '/./', '/../' 以及多余的 '/' 并返回规范化后的绝对路径名。返回的路径中没有符号连接,'/./' 或 '/../' 成分。 realpath() 失败时返回 FALSE,比如说文件不存在的话。在 BSD 系统上,如果仅仅是 path 不存在的话,PHP 并不会像其它系统那样返回 FALSE。
查手册。