Jump to content

Keeping Certain Backslashes


shadowayex

Recommended Posts

I'm creating a nice communication system that includes the use of mysql_real_escape_string(). I use stringslashes() to get rid of the slashes that are put into the database when it is pulled back out, but stripslahes actually takes out backslashes the user types. I would like to keep those particular ones. I've tried using regular expreessions to get around this, but I can seem to find a pattern to get around this. Anyone have any ideas? They don't have to be with the use of regular expressions. Anything would help.

Link to comment
Share on other sites

You should be stripping the slashes before you put the data in. Using mysql_real_escape_string shouldn't add any slashes to your actual data, it only makes it so that the query works correctly. If you have slashes in the data that means they were there before you used mysql_real_escape_string, so you should remove them at that point. When you get form data you should check if magic quotes is enabled and strip the slashes if so, magic quotes will automatically add slashes to the form data. e.g.:

$var = $_POST['var'];if (magic_quotes_gpc())  $var = stripslashes($var);

Link to comment
Share on other sites

Oh, so it's something completely different making the slashes. I thought it was myslq_real_escape_string() doing it. I'm going to test you solution and hope it works. It makes sense. I'll return with the results.

Link to comment
Share on other sites

Is there any reason I would ever need magic quotes?Edit: I think I answered my own question. In the case that I would ever need to escape data, I could just use addslashes(), right?Edit 2: With the use of .htaccess, is there a particular place I need to put this file? I have it in my site's directory, is that fine?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...