Tenatious
Tenatious

Reputation: 889

URL Get Incorrect

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 \?

Upvotes: 0

Views: 88

Answers (4)

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
}

Upvotes: 1

Jacek Sokolowski
Jacek Sokolowski

Reputation: 597

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.

Upvotes: 1

Jørgen R
Jørgen R

Reputation: 10806

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']);

Upvotes: 1

nickhar
nickhar

Reputation: 20893

stripslashes($_GET['eventtype']);

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

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

Upvotes: 1

Related Questions