Working with ampersands in $_GET functions(在 $_GET 函数中使用 符号)
问题描述
如果我有一个像 asdf.com/index.php?a=0&b=2 这样的 URL,那么对于 a
使用 $_GET 将是 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()
所以 &
变成了 %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' => '牛排和奶酪')
.
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 函数中使用 & 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 $_GET 函数中使用 & 符号


基础教程推荐
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01