开发者

quick function to replace ' with \' in php

开发者 https://www.devze.com 2023-01-10 06:01 出处:网络
Having a mental block.... I know this is开发者_如何学运维 so easy.... but nothing is going my way today!

Having a mental block....

I know this is开发者_如何学运维 so easy.... but nothing is going my way today!

Can anyone help me with a quick function to search a string and escape all apostrophes in php. Thanks.


You can use:

$changed_string = str_replace("'","\\'",$input_string)

You can also make use of the library function addslashes. Remember it will add slashes in front of single quote ('), double quote ("), backslash () and NULL.


addslashes


Use str_replace:

$str = ...
$str = str_replace("'", "\\'", $str);
0

精彩评论

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

关注公众号