0

I have the following URL:

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

and when I use

$_GET['eventtype'];

it is showing as Don\'t but I can't work out why the \ is there or how to get rid of it. None of the other % symbols seem to have the \, only the '.

How do I remove this \?

Tenatious
  • 849
  • 4
  • 12
  • 32

4 Answers4

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

or, if you've not url-decoded the var:

stripslashes(urldecode($_GET['eventtype']));
nickhar
  • 19,981
  • 12
  • 60
  • 73
1

The backslash is an escape character that's added to prevent strings from breaking.

Imagine

$str = 'Don't';

To remove the backslash, use the method stripslashes

$str = stripslashes($_GET['eventtype']);
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
1

That's because of magic_quotes_gpc.

You can disable it by adding into your .htaccess file this line:

php_flag magic_quotes_gpc Off

or just change magic_quotes_gpc value to Off in your php.ini file.

Jacek Sokolowski
  • 597
  • 4
  • 11
1

The backslash is added automatically in your $_GET and $_POST variables because you have PHP magic_quotes ini option active. That directive is deprecated and instead it's recommended to do the escaping when needed by the user instead of automatically, you might be using an old PHP version for that option to be on .

You can write portable code if your code will be use with a recent PHP version this way:

if (get_magic_quotes_gpc()) { //if magic quotes is active
   stripslashes($_GET['eventtype']); //remove escaping slashes
}
Nelson
  • 49,283
  • 8
  • 68
  • 81