开发者

quick function to replace ' with \' in php

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜