How to add a backslash before single quotes using preg_replace() php functio开发者_JS百科n ?
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.
just use the function str_replace to replace every instance of ' to \'
精彩评论