如何使用没有字段名称的get方法?
例如链接是: http://www.test.com/abc.php?config.scp
是否可以在php程序中获取“config.scp”值?谢谢!
for example the link is:
http://www.test.com/abc.php?config.scp
Is it possible to get the value "config.scp" in the php program? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该数据包含在
$_SERVER['QUERY_STRING']
中That data is contained in
$_SERVER['QUERY_STRING']
如果您想要一个简单的字符串,请使用
$_SERVER['QUERY_STRING']
。如果您仍然需要包含其余变量的数组,请使用
$_GET
。如果您var_dump( $_GET )
您提供的链接,您应该得到:您现在可以轻松解析它。
不过,在该特定查询字符串中存在一个带有点的问题。 PHP变量不能包含点,所以改为
_
。If you want a simple string, use
$_SERVER['QUERY_STRING']
.If you still need an array with rest of the variables, use
$_GET
. If youvar_dump( $_GET )
on link you provided, you should get:You can easily parse it now.
There's one gotcha with dot in that particular query string tho. PHP variables cannot contain dots, so it's changed into
_
.是...在这种情况下,数据是字段名称,但请注意 $_GET 数组索引中不允许使用点。
此外,您可以使用
&
字符分解$_SERVER['QUERY_STRING']
,并在结果数组中查找所需元素的值。Yes... in that case data is field name but be aware that dot is not allowed in $_GET array index.
Also, you can explode
$_SERVER['QUERY_STRING']
with&
character and look into resulting array for element's value you need.Hy
请参阅此示例:
$url = 'http://www.test.com/abc.php?config.scp';
$p_url = end(explode('?', $ url));
echo $p_url;
Hy
See this example:
$url = 'http://www.test.com/abc.php?config.scp';
$p_url = end(explode('?', $url));
echo $p_url;