网址不正确

时间:2012-10-23 21:46:02

标签: php urlencode urldecode

我有以下网址:

/eventfunctions.php?eventtype=Don%27t+Touch+The+Floor

当我使用

$_GET['eventtype'];

它显示为不要,但我无法理解为什么\有或如何摆脱它。没有其他%符号似乎有\,只有'。

如何删除此\?

4 个答案:

答案 0 :(得分:1)

stripslashes($_GET['eventtype']);

或者,如果你没有url解码var:

stripslashes(urldecode($_GET['eventtype']));

答案 1 :(得分:1)

反斜杠是一个转义字符,用于防止字符串断开。

想象

$str = 'Don't';

要删除反斜杠,请使用方法stripslashes

$str = stripslashes($_GET['eventtype']);

答案 2 :(得分:1)

这是因为 magic_quotes_gpc

您可以通过在此行中添加.htaccess文件来禁用它:

php_flag magic_quotes_gpc Off

或者只是在php.ini文件中将magic_quotes_gpc值更改为Off。

答案 3 :(得分:1)

反斜杠会自动添加到$_GET$_POST变量中,因为您已激活PHP magic_quotes ini选项。该指令已被弃用,而建议在用户需要时进行转义而不是自动转义,您可能使用旧版本的PHP版本 on

如果您的代码将以这种方式与最近的PHP版本一起使用,则可以编写可移植代码:

if (get_magic_quotes_gpc()) { //if magic quotes is active
   stripslashes($_GET['eventtype']); //remove escaping slashes
}
相关问题