替换str_replace中的反斜杠

时间:2013-12-01 17:22:23

标签: php replace str-replace backslash

我有以下字符串:

$text = 'Some slash\'s';

这是我的字符串替换:

$text = str_replace('\'','\\\'',$text);

我最终想要的是:

$text = 'Some slash\\\'s';

我认为我做错了。

1 个答案:

答案 0 :(得分:1)

我不知道您为什么要这样做,但我认为以下内容应该有效:

$text = str_replace('\'', "\\\\\\'", $text);