使用 PHP 中的查询字符串获取当前 URL 路径 [英] Get current URL path with query string in PHP

查看:28
本文介绍了使用 PHP 中的查询字符串获取当前 URL 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从当前请求的 URL 中获取路径.例如,如果当前 URL 是:

I need to get the path from the URL of the current request. For example, if the current URL is:

"http://www.example.com/example/test/hi.php?randomvariable=1"

我想要这个:

"/example/test/hi.php?randomvariable=1"

推荐答案

您需要 $_SERVER['REQUEST_URI'].来自文档:

为访问此页面而提供的 URI;例如,'/index.html'.

'REQUEST_URI'

The URI which was given in order to access this page; for instance, '/index.html'.

这篇关于使用 PHP 中的查询字符串获取当前 URL 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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