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