开发者

Escaping backslashes in php no matter how many \ in string

I'm very new to PHP. Currently,I'm facing one issue to escape \ and store in mysql DB. eg., If the string is like $str = \\aaaa\bbb\\\cccc$$ , I would like to save that string in DB . However, I don't know how to escape those backslashes. Please help 开发者_StackOverflow社区me settle it.


Your best option is to use prepared statements (e.g. through PDO):

$dbh = new PDO(…);
$sth = $dbh->prepare('INSERT INTO `yourtable` ( `column` ) VALUES ( :string )');
$sth->execute(array(':string' => '\\aaaa\bbb\\\cccc$$'));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜