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);
精彩评论