Gtranslate插件在撇号之前添加反斜杠

时间:2012-05-07 23:14:19

标签: php javascript

我正在为客户端网站使用 Gtranslate 插件并使用撇号翻译一些单词我发现该插件在它之前添加了反斜杠:

您好我要去吃饭......

如何在撇号之前删除反斜杠?

我可以在插件中添加一个php修复,还是应该使用javascript解决方案?

在这两种情况下,你能帮我找到一个好办法吗?

感谢。

1 个答案:

答案 0 :(得分:2)

Javascript中的正则表达式可以删除所有反斜杠,但可能存在字符串确实意味着使用反斜杠的情况。然后,您需要进行更具体的更改,从\''

http://jsfiddle.net/scx8t/

​s = "I\\'m Bob and you\\'re Jane\\\\'s mother";
document.write("before: " + s + "<br>")

s = s.replace(/\\/g, "")​​​​​​​​​​​​​​​​​​​​​​​​​​;
​document.write("after: " + s);

专门替换\&#39;写s.replace(/\\'/g, "'")

对于此斜杠/,您可以s.replace(/\//g, "")s.replace(/[\/\\]/g, "")编写preg_replace

编辑:对于此应用程序,PHP <?php $str = 'I\\\'m Joe, you\\\'re Sara'; $str = preg_replace('/\\/', '', $str); // I'm not sure if the g goes at the end of the pattern to replace all. echo $str; ?> 似乎更合适。我现在还没有运行PHP,所以我写了Javascript:P这里应该是什么样的:

/\\/

注意 /\\/g可能需要{{1}}。我不熟悉PHP。

from here示例#4剥离空白

相关问题