Jump to content

Stripping backslashes


c_shelswell

Recommended Posts

Hi,

 

I'm sure this must be pretty easy I just don't know how to do it. How do i stop stripbackslashes from removing backslashes that a user has actually inputted? Eg a user can enter a backslash but then on returning to the page becuase i have stripbackslashes cant see the ones that should be there.

 

Cheers

Link to comment
Share on other sites

Only use stripslashes() on data that has had slashes added because of addslashes() or one of the magic quotes settings. If your form data has not been processed by either addslashes() or one of the magic quotes settings, don't use stripslashes() on it.

 

As a side note, all the magic quotes settings have been removed in php6, so everyone won't need to work around the problem of needing to remove the slashes automatically put in by php.

Link to comment
Share on other sites

Trouble is I'm allowing a user to edit what they've typed so for instance. They might type "this is a \" then if they edit it they type "this is a \\" i've added it to the db using mysql_real_escape_string now when i show the entry again it's stripped the extra backslash.

 

Any ideas? Cheers

Link to comment
Share on other sites

If someone enters "some text with \" in it", mysql_real_escape_string() will convert that to "some text with \\\" in it". When that is inserted into the database it will be identical to the original (the extra slashes are not inserted into the database.)

 

When this is retrieved, you will get the original - "some text with \" in it"

 

If you are getting anything else in the input, it means that magic_quotes_gpc is on and is escaping the data from the form. If you are getting anything else when you retrieve the data, it means that magic_quotes_runtime is on.

 

Unfortunately, stripslashes() appears to be broken in the current php5 version and all slashes are removed. Double slashes \\ are not converted to a single \ anymore.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.