View Full Version : stripslashes help

12-08-2010, 10:37 PM
I have the following code:

$message = mysql_real_escape_string(stripslashes($_POST['message']));

If I put the following text in a text field and submit it my output is:
This is a test email. Please respond to this. Thank\'s for understanding.

How can I get the slash out of the output?

Thanks in advance.

12-08-2010, 10:44 PM
I'm not sure that I follow what you're trying to do. Maybe more code would give a better perspective. But from what I can see:

Obviously the stripslashes() function will remove slashes, but then you are using mysql_real_escape_string which puts them back. Are you using this in a mysql query? If not, I would just take out the mysql_real_escape_string() function, and the problem should be solved.

I always seem to have problems with slashes. They can be tricky.

12-08-2010, 10:45 PM
Stripslashes should only be used in the event that magic_quotes_gpc is enabled. Otherwise you will strip out intended escape characters.
This isn't enough information. Once you have retrieve the message from the textarea, is it then presented to the database and later retrieved and displayed, or are you saying it does this immediately after printing it without storing in the database.
If its coming from a database, check to ensure that mysql_real_escape_string has not been called twice. If you check your dataset itself, it should be without the escape characters in the database.
If it doesn't have the escape characters in the database yet still shows with them in the textarea, check the runtime configurations for magic_quotes_runtime. Those should be set to 0. Unlike magic_quotes_gpc though, the magic_quotes_runtime can be disabled at any level.