在$ _GET函数中使用&符号 [英] Working with ampersands in $_GET functions

查看:158
本文介绍了在$ _GET函数中使用&符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个类似asdf.com/index.php?a=0&b=2的网址,那么使用$ _GET作为 a 应该是0,而对于 b 会是2.但是,我放入一个$ _GET函数的术语已经有一个和号,例如a = Steak& Cheese。有没有一种方法可以使&符号在没有$ _GET变量的情况下工作,当&符号出现时它认为它的工作结束了(因此不会拉整个词)?

If I have a URL like asdf.com/index.php?a=0&b=2, then using $_GET for a would be 0 and for b would be 2. However, the term I put into a single $_GET function has an ampersand in it already, like a=Steak&Cheese. Is there a way to make ampersands work without the $_GET variable thinking its job ends when the ampersand shows up (therefore not pulling the entire term)?

推荐答案

urlencode() it & 变为%26

如果您需要使用某些参数创建查询字符串,则可以使用 http_build_query() ,它会为您的参数进行URL编码。

If you need to make a query string out of some parameters, you can use http_build_query() instead and it will URL encode your parameters for you.

在接收端, $ _ GET 值将由PHP解码,因此查询字符串 a = Steak%26Cheese 对应于 $ _ GET = array('a'=>'Steak& Cheese')

On the receiving end, your $_GET values will be decoded for you by PHP, so the query string a=Steak%26Cheese corresponds to $_GET = array('a' => 'Steak&Cheese').

这篇关于在$ _GET函数中使用&符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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