我得到的网址为test.php?value=%22hello%22
,当我打印出它显示的值\"hello\"
和$_REQUEST['value'][0]
是\
。为什么?我如何解决这个问题(正确)?为什么从url的双引号转义到PHP?
0
A
回答
4
最有可能的原因是您打开了magic quotes。你应该:
- 升级到PHP 5.4 或
- 在你的PHP配置文件disable them或
- 禁用它们在你的Apache配置(同一个链接)或
- (最后一招)测试以查看它们是否已打开,然后在输入上运行
stripslashes
。
1
如果你不能保证环境,让重新配置,你可以使用这个可重用的代码递归到$ _GET挖,$ _ POST阵列或的stripslashes清除它们:
class de_slasher {
function recursive_stripslashes($a) {
$b = array();
foreach($a as $k => $v) {
$k = stripslashes($k);
if(is_array($v)) {
$b[$k] = $this->recursive_stripslashes($v);
} else {
$b[$k] = stripslashes($v);
}
}
return($b);
}
function check_and_fix_magic_quotes(&$array) {
if(get_magic_quotes_gpc()) {
$array = $this->recursive_stripslashes($array);
}
}
function __construct($auto = false) {
if($auto === true) {
$this->check_and_fix_magic_quotes($_POST);
$this->check_and_fix_magic_quotes($_GET);
}
}
}
要使用,只需包含该类,并调用$slasher = new de_slasher(true);
来自动清理$ _GET和$ _POST。这只有在魔术引号设置打开的情况下才会发生。如果实例化类没有“真正”的参数,那么你可以选择深层过滤器的任何阵列:
$my_array = array("name" => "Herbert\'s Apple");
$slasher = new de_slasher();
$slasher->check_and_fix_magic_quotes($my_array);
相关问题
- 1. 为什么bash将单引号添加到转义命令的双引号中
- 2. 为什么bash将双引号转换为单引号?
- 3. 什么是转义引号在php
- 4. 更新PHP PDO转义双引号
- 5. XSLT 1.0:转义双引号
- 6. 转义双引号修复
- 7. Response.GetResponseStream()转义双引号
- 8. 转义双引号在sed
- 9. PHP数组转换为双引号
- 10. 双引号到asp.net mvc url
- 11. 比较中单引号与双引号的意义是什么?
- 12. 将双引号转换为单引号
- 13. php - 将单引号字符串转换为双引号
- 14. 为什么单引号显示为双引号?
- 15. php中的转义引号
- 16. 转义双引号tcsh的别名
- 17. 转义引号 - 从PHP4转移到PHP5
- 18. PHP JSON字符串,转义JS输出的双引号
- 19. PHP回声 - 转义引号
- 20. 转义引号PHP和MySQL
- 21. 在Rails中转义双引号link_to
- 22. Logstash JSON输入与转义双引号
- 23. 在Linux中perl中转义双引号
- 24. C#转义字符串双引号
- 25. jQuery和Smarty函数转义双引号
- 26. 转义双引号和网页
- 27. 转义双引号命令提示符
- 28. 使用HttpWebResponse接收转义双引号
- 29. 在Common Lisp中转义双引号
- 30. iPhone - Localizable.strings用双引号转义字符
咦,那很烂(我不能改变服务器的配置,所以我现在必须使用'php.ini'的)。谢谢! – chacham15 2013-04-22 20:09:04