Forum Moderators: coopster
I know I could escape every single one with a backslash, but that just seems really clumbsy to me. Isn't there a way to just make php take the string verbatim?
$string = str_replace('"', '\"', $string);
[for clarification, that is ... (singlequote doublequote singlequote, single \double single, $string)]
Now I haven't actually tested this little bit of code, but I know that the function itself is very handy. The part I am not sure about is using the singlequotes around the doublequote ('"'), but I am pretty sure that will work nicely.
One thing that I have used this for in the past is for inputting names into a database. I had a problem with names that had apostrophes in them (like O'Neil). I used the following which is very similar:
$LAST_NAME = str_replace("'", "\'", $LAST_NAME);
If you ever need to change it back, just follow the same methodology to restore the string. I believe that this will produce the same result as the adddslashes function, I just haven't used the addslashes function b4. In any event, they are both one line of code. Its more of a programming style than anything there, so take your pick.
Hope that helps.
Josh