How to add a backslash before single quotes using preg_replace() php function ?
+4
A:
In case you are not trying to escape Database input:
$string = str_replace("'", "\\'", $string);
In case you are:
Please consider using the appropriate escaping function. (E.g. mysql_real_escape_string) or just use prepared statements.
edorian
2010-07-20 12:08:32
+1 for "Please consider using the appropriate escaping functions".
NawaMan
2010-07-20 12:11:22
A:
just use the function str_replace to replace every instance of ' to \'
dejavu
2010-07-20 12:10:22