【问题标题】:Replace character with special characters用特殊字符替换字符
【发布时间】:2014-10-30 07:50:39
【问题描述】:

我有这样的事情:

$x = "#frac {2} {3}";

我尝试了这段代码,但不起作用:

$x = str_replace("#","\"",$x);

我想在这个字符串中用 \ 替换 #。但我不能使用 str_replace。

有什么帮助吗?

【问题讨论】:

  • 试试 ´$x = str_replace("#","\\",$x);´
  • 你在转义引号而不是反斜杠

标签: php


【解决方案1】:

您将 # 替换为 "
要在字符串中使用反斜杠,您需要对其进行转义。
How do you make a string in PHP with a backslash in it?

$x = "#frac {2} {3}";
$x = str_replace("#", "\\", $x);

【讨论】:

    猜你喜欢
    • 2014-11-03
    • 1970-01-01
    • 2015-07-10
    • 2019-09-23
    • 2011-12-28
    • 1970-01-01
    • 2021-11-17
    相关资源
    最近更新 更多