Php 替换str_replace中的反斜杠

Php 替换str_replace中的反斜杠,php,replace,str-replace,backslash,Php,Replace,Str Replace,Backslash,我有以下字符串: $text='Some slash's' 这是我的字符串替换: $text=str\u replace('\'','\\'',$text) 我想要的结果是: $text='Some slash\\\'s' 我想我做错了什么。我不知道你为什么要这么做,但我认为以下方法应该有效: $text = str_replace('\'', "\\\\\\'", $text); 反斜杠疯狂:$text=str\u replace(“\”,$text”)@AmalMurali为什么不发布答案

我有以下字符串:

$text='Some slash's'

这是我的字符串替换:

$text=str\u replace('\'','\\'',$text)

我想要的结果是:

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


我想我做错了什么。

我不知道你为什么要这么做,但我认为以下方法应该有效:

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

反斜杠疯狂:
$text=str\u replace(“\”,$text”)@AmalMurali为什么不发布答案?@AmalMurali同意。它工作得很好。得到你应得的荣誉@当然可以。在下面贴出答案:)