PHP:获取页面URL参数减 [英] PHP: Get Page URL minus arguments
问题描述
我如何获取当前页面的URL减去所有的得到的参数(废话= 2及?blah4 = 90 ...)
我知道我能得到完整的URL以$ _ SERVER ['REQUEST_URI'],但我想知道是否有一些更适合我的需要。
How do i get the URL of the current page minus all of the get arguments (?blah=2&blah4=90...) I know i can get the full URL with $_SERVER['REQUEST_URI'] but i was wondering if there was something that more fit my needs.
或者我应该只是做strpos?和SUBSTR砍的争论? (我想,一个$ _ SERVER变种会更有效 - 如果存在的话)
Or should i just do strpos ? and substr to chop of the arguments? ( i imagine that a $_SERVER var would be more efficient - if one exists)
感谢
推荐答案
$ _ SERVER ['REQUEST_URL']
有时,答案是简单的:)我发现这里的解决方案:的http:// php.net/manual/en/reserved.variables.server.php~~V 通过CTRL + F'ing为查询。
Sometimes answers are easy :) I found the solution here: http://php.net/manual/en/reserved.variables.server.php by CTRL+F'ing for "query".
修改
由于matchu在评论中说,并不是所有的服务器都支持REQUEST_URL。在这种情况下,我会用更优雅的的strtok($网址,'?');
As matchu said in the comments, not all servers support REQUEST_URL. In that case I would use the much less elegant strtok($url, '?');
.
这篇关于PHP:获取页面URL参数减的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!