PHP URL 目录 [英] PHP URL Directory

查看:17
本文介绍了PHP URL 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果网址如下:

如果:http://www.imvu-e.com/products/dnr/
然后:http://www.imvu-e.com/products/dnr/

如果:http://www.imvu-e.com/products/dnr/?
然后:http://www.imvu-e.com/products/dnr/

如果:http://www.imvu-e.com/products/dnr/index.php
然后:http://www.imvu-e.com/products/dnr/

如果:http://www.imvu-e.com/products/dnr/page.php?var=2
然后:http://www.imvu-e.com/products/dnr/

如果:http://www.imvu-e.com/products/dnr
然后:http://www.imvu-e.com/products/

我该怎么做?

我的尝试:

print "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI'])."/";

推荐答案

看看 parse_url() 函数.

Have a look at parse_url() function.

它返回任何你需要的东西.

It returns anything you need.

简单地print_r() parse_url 的结果,看看你得到了什么.你可能想要这样的东西:

Simply print_r() the result from parse_url to see what you get back. You probably want something like:

$ARRurlParts = parse_url($orgurl);

$newURL = $ARRelem["scheme"].
"://".$ARRelem["host"].
((isset($ARRelem["port"]))?":".$ARRelem["port"]:"").
$ARRelem["path"];

这篇关于PHP URL 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆