Reputation: 18617
My PHP application adds backslashes to quotes in many locations with addslashes()
. Unfortunately, this adding has produced output akin to the following.
Every time I refresh my page, this string increases in number of back slashes.
don't
don\'t
don\\'t
don\\\\'t
don\\\\\\\\'t
and so on.
I want to write a function that deletes all these extra back slashes. I have tried
str_replace($text, "\\\\", "");
to no avail.
Upvotes: 0
Views: 196
Reputation: 526613
What happens if your actual value happens to include \\
legitimately? For instance, if your content were referring to a Windows-style share reference - \\192.168.1.1\foo
. If you blindly strip out any double slashes, you'll strip out ones that are meant to be there, as well.
The "right" answer is really to not add slashes to things that don't need them. You should know whether a given value is already escaped or not (after all, you're the one controlling where every value comes from, and what it's being used for) and only add slashes when you need them.
Upvotes: 1