PHP检查URL是否包含查询字符串 [英] PHP to check if a URL contains a query string

查看:237
本文介绍了PHP检查URL是否包含查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很容易.似乎有很多解决方案可以确定URL是否包含特定的键或值,但是奇怪的是,我找不到用于确定URL是否具有查询的解决方案.

This is an easy one. There seem to be plenty of solutions to determine if a URL contains a specific key or value, but strangely I can't find a solution for determining if URL does or does not have a query at all.

使用PHP,我只想检查一下当前URL是否具有查询字符串.例如: http://abc.com/xyz/?key=value VS. http://abc.com/xyz/.

Using PHP, I simply want to check to see if the current URL has a query string. For example: http://abc.com/xyz/?key=value VS. http://abc.com/xyz/.

推荐答案

对于任何URL作为字符串:

For any URL as a string:

if (parse_url($url, PHP_URL_QUERY))

http://php.net/parse_url

如果用于当前请求的URL ,只需:

if ($_GET)

这篇关于PHP检查URL是否包含查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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