开发者

using preg_replace to add backslash before single quote

开发者 https://www.devze.com 2023-01-08 05:48 出处:网络
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:

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 \'

0

精彩评论

暂无评论...
验证码 换一张
取 消