简体   繁体   English

使用preg_replace在单引号之前添加反斜杠

[英]using preg_replace to add backslash before single quote

如何使用preg_replace()php函数在单引号前添加反斜杠?

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. 请考虑使用适当的转义功能。 (Eg mysql_real_escape_string) or just use prepared statements. (例如mysql_real_escape_string)或只使用准备好的语句。

只需使用功能str_replace将'的每个实例替换为\\'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM