Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I go about adding slashes to only single quotes and ignoring double quotes?

How should I go about adding slashes to only single quotes and ignoring double quotes? I am using php. I would only like to escape single quotes to prevent my php mysql queries from breaking.

Thank you!

Edit: I am thinking a regular expression search and replace will be the most helpful.

like image 228
atwellpub Avatar asked May 02 '10 18:05

atwellpub


1 Answers

Okay am really late to this post but adding this answer hoping that it might help someone landing at this question. While @Weston C has given a regex solution, there is a php function for doing this- addcslashes (http://php.net/manual/en/function.addcslashes.php):

string addcslashes ( string $str , string $charlist )
Returns a string with backslashes before characters that are listed in charlist parameter.
like image 80
Ninja Avatar answered Oct 05 '22 16:10

Ninja