st4ck0v3rfl0w
st4ck0v3rfl0w

Reputation: 6755

Remove escaping slashes before single or double quote characters

So I'm using Wordpress' database object to store things into tables. One of the drawbacks (or advantages, depending on how you look at it) is that it escapes the single and double quote characters so that:

' --> \'
" ---> \"

What regex can I apply to the output to replace all \' with ' and \" with "?

Upvotes: 0

Views: 40

Answers (2)

kennytm
kennytm

Reputation: 523184

Use stripslashes

$newstr = stripslashes($str);

Note that stripslashes will replace \\ by \ as well. If you don't want this, you could use str_replace:

$newstr = str_replace(array('\\\'', '\\"'), array('\'', '"'), $str);

Upvotes: 2

codaddict
codaddict

Reputation: 454960

You can try using stripslashes

Upvotes: 3

Related Questions